@hcmai/cli 0.4.6 → 0.4.8
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 +213 -95
- 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);
|
|
@@ -6429,6 +6429,9 @@ async function workspaceValidateCommand(args) {
|
|
|
6429
6429
|
exitWorkspaceError(e);
|
|
6430
6430
|
}
|
|
6431
6431
|
}
|
|
6432
|
+
function isScriptPath(relativePath) {
|
|
6433
|
+
return relativePath.startsWith("scripts/");
|
|
6434
|
+
}
|
|
6432
6435
|
async function workspacePushCommand(args) {
|
|
6433
6436
|
try {
|
|
6434
6437
|
const rootDir = resolveRootDir(args.dir);
|
|
@@ -6437,6 +6440,24 @@ async function workspacePushCommand(args) {
|
|
|
6437
6440
|
const client3 = HcmClient17.fromAuthContext(
|
|
6438
6441
|
await getActiveAuthContextFromCli(args, { fallbackEnv: context.profile })
|
|
6439
6442
|
);
|
|
6443
|
+
const activeWorkspaceKey = args.dryRun ? null : await probeActiveWorkspaceKey(client3);
|
|
6444
|
+
if (!args.dryRun && context.workspaceKey && activeWorkspaceKey !== context.workspaceKey) {
|
|
6445
|
+
const plan = await pushWorkspaceRawFiles({
|
|
6446
|
+
http: client3.raw(),
|
|
6447
|
+
rootDir,
|
|
6448
|
+
context,
|
|
6449
|
+
dryRun: true
|
|
6450
|
+
});
|
|
6451
|
+
const scriptOps = plan.operations.filter((op) => isScriptPath(op.remotePath ?? op.localPath));
|
|
6452
|
+
if (scriptOps.length > 0) {
|
|
6453
|
+
throw new Error(
|
|
6454
|
+
`\u672C\u6B21\u4F1A\u5199 ${scriptOps.length} \u4E2A\u811A\u672C\uFF0C\u4F46\u5F53\u524D\u6FC0\u6D3B\u7684\u5F00\u53D1\u7A7A\u95F4\u662F ${activeWorkspaceKey ? `"${activeWorkspaceKey}"` : "\uFF08\u672A\u6FC0\u6D3B\uFF09"}\uFF0C\u4E0D\u662F\u672C\u7A7A\u95F4 "${context.workspaceKey}"\u3002
|
|
6455
|
+
\u670D\u52A1\u7AEF\u4F1A\u62D2\u7EDD\u5199\u811A\u672C\uFF0C\u800C\u975E\u811A\u672C\u6587\u4EF6\u5DF2\u7ECF\u5199\u8FDB\u53BB\u4E86 \u2014\u2014 \u90A3\u4F1A\u7559\u4E0B\u534A\u63A8\u9001\u72B6\u6001\u3002
|
|
6456
|
+
\u4E0B\u4E00\u6B65\uFF1Ahcm workspace activate ${context.workspaceKey}
|
|
6457
|
+
\u6D89\u53CA\u811A\u672C\uFF1A${scriptOps.map((op) => op.remotePath ?? op.localPath).join(", ")}`
|
|
6458
|
+
);
|
|
6459
|
+
}
|
|
6460
|
+
}
|
|
6440
6461
|
const rawResult = await pushWorkspaceRawFiles({
|
|
6441
6462
|
http: client3.raw(),
|
|
6442
6463
|
rootDir,
|
|
@@ -6454,11 +6475,7 @@ async function workspacePushCommand(args) {
|
|
|
6454
6475
|
}
|
|
6455
6476
|
writeWorkspacePushResult(rawResult, results, args.output ?? "table");
|
|
6456
6477
|
const hint = activationHint(
|
|
6457
|
-
await probeActiveWorkspaceKey(
|
|
6458
|
-
HcmClient17.fromAuthContext(
|
|
6459
|
-
await getActiveAuthContextFromCli(args, { fallbackEnv: context.profile })
|
|
6460
|
-
)
|
|
6461
|
-
),
|
|
6478
|
+
activeWorkspaceKey ?? await probeActiveWorkspaceKey(client3),
|
|
6462
6479
|
context.workspaceKey ?? null
|
|
6463
6480
|
);
|
|
6464
6481
|
if (hint) process.stderr.write(`
|
|
@@ -7484,6 +7501,8 @@ async function identityRemove(name) {
|
|
|
7484
7501
|
|
|
7485
7502
|
// src/commands/delivery-action-policy.ts
|
|
7486
7503
|
init_auth_guard();
|
|
7504
|
+
import { existsSync as existsSync2 } from "fs";
|
|
7505
|
+
import { join as pathJoin } from "path";
|
|
7487
7506
|
import {
|
|
7488
7507
|
HcmClient as HcmClient18,
|
|
7489
7508
|
formatObject as formatObject19
|
|
@@ -7508,7 +7527,17 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
|
|
|
7508
7527
|
"cache-mutation",
|
|
7509
7528
|
"setting-write",
|
|
7510
7529
|
"credential-reset",
|
|
7511
|
-
"action-write"
|
|
7530
|
+
"action-write",
|
|
7531
|
+
// workspace 侧只收**输入可完整绑进计划**的那两个:它们的入参是 workspace key,
|
|
7532
|
+
// 没有外部载荷文件。
|
|
7533
|
+
//
|
|
7534
|
+
// 🔴 刻意不收 workspace-push / metadata-write / workspace-local-change:
|
|
7535
|
+
// push 读的是整个本地目录、meta set 读 --file 指向的任意文件,而载荷绑定只覆盖
|
|
7536
|
+
// --data-file / --params-file(PAYLOAD_FILE_FLAGS)。绑不住就意味着「批准时看到的内容」
|
|
7537
|
+
// 与「执行时实际读到的内容」可以不同 —— 那正是受控执行要挡住的东西。
|
|
7538
|
+
// 要收它们,得先把目录/文件载荷也纳入绑定与 assertPayloadsUnchanged。
|
|
7539
|
+
"workspace-create",
|
|
7540
|
+
"workspace-activate"
|
|
7512
7541
|
]);
|
|
7513
7542
|
function assessDeliveryCommand(inputArgv, options = {}) {
|
|
7514
7543
|
const argv = inputArgv[0] === "--" ? inputArgv.slice(1) : [...inputArgv];
|
|
@@ -7849,9 +7878,26 @@ async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
|
7849
7878
|
const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
|
|
7850
7879
|
return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
|
|
7851
7880
|
}
|
|
7881
|
+
function withProjectReadiness(assessment, projectRoot = ".") {
|
|
7882
|
+
const projectFile = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
|
|
7883
|
+
const projectInitialized = existsSync2(projectFile);
|
|
7884
|
+
if (projectInitialized || !assessment.guardedExecutionAvailable) {
|
|
7885
|
+
return { ...assessment, projectInitialized };
|
|
7886
|
+
}
|
|
7887
|
+
const requirements = [...assessment.requirements ?? []];
|
|
7888
|
+
if (!requirements.includes("delivery-project")) requirements.push("delivery-project");
|
|
7889
|
+
return {
|
|
7890
|
+
...assessment,
|
|
7891
|
+
projectInitialized,
|
|
7892
|
+
requirements,
|
|
7893
|
+
modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
|
|
7894
|
+
projectNextStep: `\u672C\u9879\u76EE\u5C1A\u672A\u521D\u59CB\u5316\uFF08\u7F3A ${projectFile}\uFF09\uFF1B\u5148\u8DD1 hcm delivery init`
|
|
7895
|
+
};
|
|
7896
|
+
}
|
|
7852
7897
|
async function deliveryAssessCommand(argv, args) {
|
|
7853
7898
|
const assessment = await assessEffectiveDeliveryCommand(argv);
|
|
7854
|
-
|
|
7899
|
+
const enriched = withProjectReadiness(assessment);
|
|
7900
|
+
process.stdout.write(formatObject19(enriched, { format: args.output ?? "json" }) + "\n");
|
|
7855
7901
|
}
|
|
7856
7902
|
async function resolveCoreAction(request) {
|
|
7857
7903
|
try {
|
|
@@ -7946,13 +7992,84 @@ function flagValue2(argv, flag) {
|
|
|
7946
7992
|
return index >= 0 ? argv[index + 1] : void 0;
|
|
7947
7993
|
}
|
|
7948
7994
|
|
|
7995
|
+
// src/commands/delivery-init.ts
|
|
7996
|
+
init_exit();
|
|
7997
|
+
import { promises as fs6 } from "fs";
|
|
7998
|
+
import path6 from "path";
|
|
7999
|
+
import { formatObject as formatObject20 } from "@hcmai/sdk";
|
|
8000
|
+
var MODES = ["plan-only", "controlled"];
|
|
8001
|
+
var SCAFFOLD_DIRS = ["work", "decisions", "evidence"];
|
|
8002
|
+
function renderProjectYml(mode) {
|
|
8003
|
+
return [
|
|
8004
|
+
"# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
|
|
8005
|
+
"#",
|
|
8006
|
+
"# deliveryMode \u51B3\u5B9A\u8FD9\u4E2A\u9879\u76EE\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
|
|
8007
|
+
"# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
|
|
8008
|
+
"# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
|
|
8009
|
+
"#",
|
|
8010
|
+
"# \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",
|
|
8011
|
+
"# \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",
|
|
8012
|
+
`deliveryMode: ${mode}`,
|
|
8013
|
+
""
|
|
8014
|
+
].join("\n");
|
|
8015
|
+
}
|
|
8016
|
+
async function deliveryInitCommand(args) {
|
|
8017
|
+
try {
|
|
8018
|
+
const mode = args.mode ?? "controlled";
|
|
8019
|
+
if (!MODES.includes(mode)) {
|
|
8020
|
+
throw new Error(
|
|
8021
|
+
`--mode \u53EA\u63A5\u53D7 ${MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
|
|
8022
|
+
\u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
|
|
8023
|
+
);
|
|
8024
|
+
}
|
|
8025
|
+
const root = path6.resolve(args.project ?? ".");
|
|
8026
|
+
const dir = path6.join(root, ".hcm-delivery");
|
|
8027
|
+
const file = path6.join(dir, "project.yml");
|
|
8028
|
+
let existed = false;
|
|
8029
|
+
try {
|
|
8030
|
+
await fs6.access(file);
|
|
8031
|
+
existed = true;
|
|
8032
|
+
} catch {
|
|
8033
|
+
existed = false;
|
|
8034
|
+
}
|
|
8035
|
+
if (existed && !args.force) {
|
|
8036
|
+
throw new Error(
|
|
8037
|
+
`\u9879\u76EE\u914D\u7F6E\u5DF2\u5B58\u5728\uFF1A${file}
|
|
8038
|
+
\u4E0D\u8986\u76D6\u5DF2\u6709\u914D\u7F6E\u2014\u2014\u5B83\u51B3\u5B9A\u672C\u9879\u76EE\u5141\u4E0D\u5141\u8BB8\u771F\u7684\u6267\u884C\u3002
|
|
8039
|
+
\u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
|
|
8040
|
+
);
|
|
8041
|
+
}
|
|
8042
|
+
await fs6.mkdir(dir, { recursive: true });
|
|
8043
|
+
await fs6.writeFile(file, renderProjectYml(mode), "utf8");
|
|
8044
|
+
const created = [];
|
|
8045
|
+
for (const sub of SCAFFOLD_DIRS) {
|
|
8046
|
+
const p = path6.join(root, sub);
|
|
8047
|
+
await fs6.mkdir(p, { recursive: true });
|
|
8048
|
+
created.push(sub + "/");
|
|
8049
|
+
}
|
|
8050
|
+
const result = {
|
|
8051
|
+
project: root,
|
|
8052
|
+
projectFile: file,
|
|
8053
|
+
deliveryMode: mode,
|
|
8054
|
+
overwritten: existed,
|
|
8055
|
+
scaffold: created,
|
|
8056
|
+
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"
|
|
8057
|
+
};
|
|
8058
|
+
process.stdout.write(formatObject20(result, { format: args.output ?? "json" }) + "\n");
|
|
8059
|
+
process.exit(0);
|
|
8060
|
+
} catch (e) {
|
|
8061
|
+
exitWithError(e);
|
|
8062
|
+
process.exit(1);
|
|
8063
|
+
}
|
|
8064
|
+
}
|
|
8065
|
+
|
|
7949
8066
|
// src/commands/delivery-doctor.ts
|
|
7950
8067
|
init_auth_guard();
|
|
7951
8068
|
init_exit();
|
|
7952
8069
|
import {
|
|
7953
8070
|
HcmClient as HcmClient19,
|
|
7954
8071
|
fetchReconIdentity,
|
|
7955
|
-
formatObject as
|
|
8072
|
+
formatObject as formatObject21,
|
|
7956
8073
|
fromAxiosError as fromAxiosError18,
|
|
7957
8074
|
httpProbe,
|
|
7958
8075
|
runDoctor
|
|
@@ -7978,7 +8095,7 @@ async function deliveryDoctorCommand(args) {
|
|
|
7978
8095
|
const report = await runDoctor(probe, identity2);
|
|
7979
8096
|
const fmt = args.output ?? "json";
|
|
7980
8097
|
if (fmt !== "json") process.stdout.write(render2(report) + "\n");
|
|
7981
|
-
process.stdout.write(
|
|
8098
|
+
process.stdout.write(formatObject21(report, { format: fmt }) + "\n");
|
|
7982
8099
|
process.exit(report.ok ? 0 : 1);
|
|
7983
8100
|
} catch (e) {
|
|
7984
8101
|
const err = e;
|
|
@@ -7996,7 +8113,7 @@ import {
|
|
|
7996
8113
|
ReconLayout,
|
|
7997
8114
|
ROUND_EXIT_CODES,
|
|
7998
8115
|
computeReconSourceKey,
|
|
7999
|
-
formatObject as
|
|
8116
|
+
formatObject as formatObject22,
|
|
8000
8117
|
fromAxiosError as fromAxiosError19,
|
|
8001
8118
|
httpProbe as httpProbe2,
|
|
8002
8119
|
inspectRound,
|
|
@@ -8016,7 +8133,7 @@ async function deliveryReconCommand(args) {
|
|
|
8016
8133
|
onlyModel: args.model ?? null,
|
|
8017
8134
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
8018
8135
|
});
|
|
8019
|
-
process.stdout.write(
|
|
8136
|
+
process.stdout.write(formatObject22(summary, { format: args.output ?? "json" }) + "\n");
|
|
8020
8137
|
} catch (e) {
|
|
8021
8138
|
const err = e;
|
|
8022
8139
|
if (err?.isAxiosError) exitWithError(fromAxiosError19(err, args.env));
|
|
@@ -8030,7 +8147,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
8030
8147
|
const result = inspectRound(args.dir ?? ".");
|
|
8031
8148
|
const fmt = args.output ?? "json";
|
|
8032
8149
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
8033
|
-
process.stdout.write(
|
|
8150
|
+
process.stdout.write(formatObject22(result, { format: fmt }) + "\n");
|
|
8034
8151
|
code = ROUND_EXIT_CODES[result.state];
|
|
8035
8152
|
} catch (e) {
|
|
8036
8153
|
exitWithError(e);
|
|
@@ -8048,14 +8165,14 @@ import {
|
|
|
8048
8165
|
GAP_REASONS,
|
|
8049
8166
|
deriveAclass,
|
|
8050
8167
|
exitCode as gate0ExitCode,
|
|
8051
|
-
formatObject as
|
|
8168
|
+
formatObject as formatObject23,
|
|
8052
8169
|
inspectRound as inspectRound2,
|
|
8053
8170
|
loadProtocolFacts,
|
|
8054
8171
|
scan
|
|
8055
8172
|
} from "@hcmai/sdk";
|
|
8056
|
-
import * as
|
|
8173
|
+
import * as path7 from "path";
|
|
8057
8174
|
function renderGate0(result, skillRoot) {
|
|
8058
|
-
const where = skillRoot ? `\uFF08${
|
|
8175
|
+
const where = skillRoot ? `\uFF08${path7.resolve(skillRoot)}\uFF09` : "";
|
|
8059
8176
|
const lines = [
|
|
8060
8177
|
`\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`
|
|
8061
8178
|
];
|
|
@@ -8093,7 +8210,7 @@ async function deliveryGate0Command(args) {
|
|
|
8093
8210
|
const merged = { ...result, premise: premise5 };
|
|
8094
8211
|
const fmt = args.output ?? "json";
|
|
8095
8212
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
8096
|
-
process.stdout.write(`${
|
|
8213
|
+
process.stdout.write(`${formatObject23(merged, { format: fmt })}
|
|
8097
8214
|
`);
|
|
8098
8215
|
for (const problem of premise5) {
|
|
8099
8216
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -8166,8 +8283,8 @@ import {
|
|
|
8166
8283
|
writeImportPlan,
|
|
8167
8284
|
writeRisk
|
|
8168
8285
|
} from "@hcmai/sdk";
|
|
8169
|
-
import { existsSync as
|
|
8170
|
-
import * as
|
|
8286
|
+
import { existsSync as existsSync3 } from "fs";
|
|
8287
|
+
import * as path8 from "path";
|
|
8171
8288
|
function premise(message, hint = "") {
|
|
8172
8289
|
process.stderr.write(message + (hint ? `
|
|
8173
8290
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -8178,7 +8295,7 @@ async function runSeedPlan(args, client3) {
|
|
|
8178
8295
|
const tenant2 = tenantOf(client3);
|
|
8179
8296
|
const work = seedWorkDir({ out, tenant: tenant2, work: args.work ?? null, mapping: args.mapping ?? null });
|
|
8180
8297
|
const mappingPath = seedMappingPath({ out, tenant: tenant2, mapping: args.mapping ?? null }, work);
|
|
8181
|
-
if (!
|
|
8298
|
+
if (!existsSync3(mappingPath)) {
|
|
8182
8299
|
return premise(
|
|
8183
8300
|
`\u8BFB\u4E0D\u5230\u5BFC\u5165\u6620\u5C04\u5DE5\u4EF6\uFF1A${mappingPath}`,
|
|
8184
8301
|
"\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"
|
|
@@ -8194,13 +8311,13 @@ async function runSeedPlan(args, client3) {
|
|
|
8194
8311
|
const reconDir = candidates[0].reconDir;
|
|
8195
8312
|
if (candidates.length > 1) {
|
|
8196
8313
|
process.stderr.write(
|
|
8197
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
8314
|
+
`\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"
|
|
8198
8315
|
);
|
|
8199
8316
|
}
|
|
8200
8317
|
const round = inspectRound3(reconDir);
|
|
8201
8318
|
process.stderr.write(roundWarning(round));
|
|
8202
8319
|
const baseline = {
|
|
8203
|
-
path: `${
|
|
8320
|
+
path: `${path8.basename(path8.dirname(reconDir))}/${path8.basename(reconDir)}`,
|
|
8204
8321
|
roundId: round.roundId ?? null
|
|
8205
8322
|
};
|
|
8206
8323
|
let exemptions = null;
|
|
@@ -8460,9 +8577,9 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
8460
8577
|
}
|
|
8461
8578
|
|
|
8462
8579
|
// src/commands/delivery-seed-find.ts
|
|
8463
|
-
import { existsSync as
|
|
8580
|
+
import { existsSync as existsSync4 } from "fs";
|
|
8464
8581
|
import { readFileSync as readFileSync5 } from "fs";
|
|
8465
|
-
import * as
|
|
8582
|
+
import * as path9 from "path";
|
|
8466
8583
|
import {
|
|
8467
8584
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
8468
8585
|
ValueHints,
|
|
@@ -8476,10 +8593,10 @@ import {
|
|
|
8476
8593
|
valuesRoundCaveat
|
|
8477
8594
|
} from "@hcmai/sdk";
|
|
8478
8595
|
function provenance(chosenReconDir, others) {
|
|
8479
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
8596
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path9.basename(chosenReconDir)}\`
|
|
8480
8597
|
`;
|
|
8481
8598
|
if (others.length > 0) {
|
|
8482
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
8599
|
+
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";
|
|
8483
8600
|
}
|
|
8484
8601
|
return `${line}
|
|
8485
8602
|
`;
|
|
@@ -8521,7 +8638,7 @@ function runSeedFind(args) {
|
|
|
8521
8638
|
const chosen = { reconDir: picked.reconDir, indexFile: picked.indexFile };
|
|
8522
8639
|
const prefix = picked.prefix;
|
|
8523
8640
|
process.stdout.write(prefix);
|
|
8524
|
-
if (!
|
|
8641
|
+
if (!existsSync4(chosen.indexFile)) {
|
|
8525
8642
|
return premise2(`\u7D22\u5F15\u6587\u4EF6\u5728\u9009\u4E2D\u4E4B\u540E\u6D88\u5931\u4E86\uFF1A${chosen.indexFile}`);
|
|
8526
8643
|
}
|
|
8527
8644
|
const { rows, problems } = loadRows(readFileSync5(chosen.indexFile, "utf-8"));
|
|
@@ -8816,7 +8933,7 @@ import {
|
|
|
8816
8933
|
runTriageRound
|
|
8817
8934
|
} from "@hcmai/sdk";
|
|
8818
8935
|
import { mkdirSync, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "fs";
|
|
8819
|
-
import * as
|
|
8936
|
+
import * as path10 from "path";
|
|
8820
8937
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
8821
8938
|
function premise4(message, hint) {
|
|
8822
8939
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -8852,8 +8969,8 @@ function renderProblems(rows) {
|
|
|
8852
8969
|
`;
|
|
8853
8970
|
}
|
|
8854
8971
|
function writeTriageArtifact(outDir, body) {
|
|
8855
|
-
const out =
|
|
8856
|
-
mkdirSync(
|
|
8972
|
+
const out = path10.join(outDir, "work", "triage.md");
|
|
8973
|
+
mkdirSync(path10.dirname(out), { recursive: true });
|
|
8857
8974
|
writeFileSync2(out, body, "utf8");
|
|
8858
8975
|
return out;
|
|
8859
8976
|
}
|
|
@@ -8893,9 +9010,9 @@ async function deliveryTriageCommand(args) {
|
|
|
8893
9010
|
// src/commands/delivery-execution.ts
|
|
8894
9011
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
8895
9012
|
import { spawn } from "child_process";
|
|
8896
|
-
import { createReadStream, promises as
|
|
8897
|
-
import
|
|
8898
|
-
import { CliError as CliError20, CliErrorCode as CliErrorCode19, formatObject as
|
|
9013
|
+
import { createReadStream, promises as fs7 } from "fs";
|
|
9014
|
+
import path11 from "path";
|
|
9015
|
+
import { CliError as CliError20, CliErrorCode as CliErrorCode19, formatObject as formatObject24 } from "@hcmai/sdk";
|
|
8899
9016
|
init_exit();
|
|
8900
9017
|
var EXECUTION_CONTRACT_VERSION = "2026-08-29.controlled-v3";
|
|
8901
9018
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -8934,11 +9051,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
8934
9051
|
};
|
|
8935
9052
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
8936
9053
|
const plan = { ...core, planId };
|
|
8937
|
-
const plansDir =
|
|
9054
|
+
const plansDir = path11.join(project, ".hcm-delivery", "execution-plans");
|
|
8938
9055
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
8939
|
-
const planFile =
|
|
9056
|
+
const planFile = path11.join(plansDir, `${planId}.json`);
|
|
8940
9057
|
try {
|
|
8941
|
-
await
|
|
9058
|
+
await fs7.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
8942
9059
|
`, {
|
|
8943
9060
|
encoding: "utf8",
|
|
8944
9061
|
mode: 384,
|
|
@@ -8955,7 +9072,7 @@ async function executeDeliveryPlan(input) {
|
|
|
8955
9072
|
if (await readProjectMode(project) !== "controlled") {
|
|
8956
9073
|
throw invalid2("\u9879\u76EE\u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212");
|
|
8957
9074
|
}
|
|
8958
|
-
const planFile =
|
|
9075
|
+
const planFile = path11.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
8959
9076
|
const plan = await readPlan(project, planFile);
|
|
8960
9077
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
8961
9078
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -8986,13 +9103,13 @@ async function executeDeliveryPlan(input) {
|
|
|
8986
9103
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
8987
9104
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
8988
9105
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
8989
|
-
const receiptFile =
|
|
9106
|
+
const receiptFile = path11.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
8990
9107
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
8991
|
-
const claimsDir =
|
|
9108
|
+
const claimsDir = path11.join(project, ".hcm-delivery", "execution-claims");
|
|
8992
9109
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
8993
|
-
const claimFile =
|
|
9110
|
+
const claimFile = path11.join(claimsDir, `${plan.planId}.json`);
|
|
8994
9111
|
try {
|
|
8995
|
-
await
|
|
9112
|
+
await fs7.writeFile(
|
|
8996
9113
|
claimFile,
|
|
8997
9114
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
8998
9115
|
`,
|
|
@@ -9049,7 +9166,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
9049
9166
|
evidenceDir: args.evidenceDir,
|
|
9050
9167
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
9051
9168
|
});
|
|
9052
|
-
process.stdout.write(
|
|
9169
|
+
process.stdout.write(formatObject24(plan, { format: args.output ?? "json" }) + "\n");
|
|
9053
9170
|
process.stderr.write(`
|
|
9054
9171
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
9055
9172
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -9070,14 +9187,14 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
9070
9187
|
planId,
|
|
9071
9188
|
argv
|
|
9072
9189
|
});
|
|
9073
|
-
process.stdout.write(
|
|
9190
|
+
process.stdout.write(formatObject24(receipt, { format: args.output ?? "json" }) + "\n");
|
|
9074
9191
|
process.exitCode = receipt.exitCode;
|
|
9075
9192
|
} catch (cause) {
|
|
9076
9193
|
exitWithError(cause);
|
|
9077
9194
|
}
|
|
9078
9195
|
}
|
|
9079
9196
|
async function readProjectMode(project) {
|
|
9080
|
-
const file =
|
|
9197
|
+
const file = path11.join(project, ".hcm-delivery", "project.yml");
|
|
9081
9198
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
9082
9199
|
const match = content.toString("utf8").match(
|
|
9083
9200
|
/^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
|
|
@@ -9089,13 +9206,13 @@ async function readProjectMode(project) {
|
|
|
9089
9206
|
return mode;
|
|
9090
9207
|
}
|
|
9091
9208
|
var SKILLS_LOCK_CANDIDATES = [
|
|
9092
|
-
|
|
9093
|
-
|
|
9209
|
+
path11.join("hcm-skills", ".hcm-skills.json"),
|
|
9210
|
+
path11.join(".claude", "skills", ".hcm-skills.json")
|
|
9094
9211
|
];
|
|
9095
9212
|
async function readSkillsLock(project) {
|
|
9096
9213
|
const found = [];
|
|
9097
9214
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
9098
|
-
if (await pathExists(
|
|
9215
|
+
if (await pathExists(path11.join(project, candidate))) found.push(candidate);
|
|
9099
9216
|
}
|
|
9100
9217
|
if (found.length === 0) {
|
|
9101
9218
|
throw invalid2(
|
|
@@ -9107,7 +9224,7 @@ async function readSkillsLock(project) {
|
|
|
9107
9224
|
`\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`
|
|
9108
9225
|
);
|
|
9109
9226
|
}
|
|
9110
|
-
const bytes = await readSafeFile(project,
|
|
9227
|
+
const bytes = await readSafeFile(project, path11.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
9111
9228
|
try {
|
|
9112
9229
|
JSON.parse(bytes.toString("utf8"));
|
|
9113
9230
|
} catch (cause) {
|
|
@@ -9120,7 +9237,7 @@ async function bindDocument(project, reference, label) {
|
|
|
9120
9237
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
9121
9238
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
9122
9239
|
}
|
|
9123
|
-
const file =
|
|
9240
|
+
const file = path11.join(project, relative2);
|
|
9124
9241
|
const bytes = await readSafeFile(project, file, label);
|
|
9125
9242
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
9126
9243
|
}
|
|
@@ -9133,11 +9250,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
9133
9250
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
9134
9251
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
9135
9252
|
}
|
|
9136
|
-
const absolute =
|
|
9253
|
+
const absolute = path11.join(project, relative2);
|
|
9137
9254
|
await assertNoSymlinkComponents(project, relative2);
|
|
9138
|
-
const stat = await
|
|
9255
|
+
const stat = await fs7.stat(absolute).catch(() => null);
|
|
9139
9256
|
if (stat === null) {
|
|
9140
|
-
await
|
|
9257
|
+
await fs7.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
9141
9258
|
throw invalid2(
|
|
9142
9259
|
`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`,
|
|
9143
9260
|
cause
|
|
@@ -9265,7 +9382,7 @@ async function bindPayloadFiles(project, argv) {
|
|
|
9265
9382
|
}
|
|
9266
9383
|
async function bindPayloadFile(project, reference, label) {
|
|
9267
9384
|
const relative2 = safeRelative(reference, label);
|
|
9268
|
-
const file =
|
|
9385
|
+
const file = path11.join(project, relative2);
|
|
9269
9386
|
const bytes = await readSafeFile(project, file, label);
|
|
9270
9387
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
9271
9388
|
}
|
|
@@ -9326,29 +9443,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
9326
9443
|
async function writeReceiptExclusive(target, receipt) {
|
|
9327
9444
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
9328
9445
|
try {
|
|
9329
|
-
await
|
|
9446
|
+
await fs7.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
9330
9447
|
`, {
|
|
9331
9448
|
encoding: "utf8",
|
|
9332
9449
|
mode: 384,
|
|
9333
9450
|
flag: "wx"
|
|
9334
9451
|
});
|
|
9335
|
-
await
|
|
9452
|
+
await fs7.link(temp, target);
|
|
9336
9453
|
} catch (cause) {
|
|
9337
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
9454
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path11.basename(target)}`, cause);
|
|
9338
9455
|
} finally {
|
|
9339
|
-
await
|
|
9456
|
+
await fs7.unlink(temp).catch(() => void 0);
|
|
9340
9457
|
}
|
|
9341
9458
|
}
|
|
9342
9459
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
9343
|
-
await assertNoSymlinkComponents(project,
|
|
9344
|
-
const existing = await
|
|
9460
|
+
await assertNoSymlinkComponents(project, path11.dirname(relative2));
|
|
9461
|
+
const existing = await fs7.lstat(absolute).catch(() => void 0);
|
|
9345
9462
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9346
9463
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
9347
|
-
if (!existing) await
|
|
9348
|
-
await
|
|
9464
|
+
if (!existing) await fs7.mkdir(absolute, { mode: 448 });
|
|
9465
|
+
await fs7.chmod(absolute, 448);
|
|
9349
9466
|
}
|
|
9350
9467
|
async function pathExists(file) {
|
|
9351
|
-
return
|
|
9468
|
+
return fs7.lstat(file).then(
|
|
9352
9469
|
() => true,
|
|
9353
9470
|
(cause) => {
|
|
9354
9471
|
if (cause.code === "ENOENT") return false;
|
|
@@ -9357,47 +9474,47 @@ async function pathExists(file) {
|
|
|
9357
9474
|
);
|
|
9358
9475
|
}
|
|
9359
9476
|
async function readSafeFile(project, file, label) {
|
|
9360
|
-
const relative2 =
|
|
9361
|
-
if (relative2.startsWith("../") ||
|
|
9477
|
+
const relative2 = path11.relative(project, file).split(path11.sep).join("/");
|
|
9478
|
+
if (relative2.startsWith("../") || path11.isAbsolute(relative2))
|
|
9362
9479
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
9363
9480
|
await assertNoSymlinkComponents(project, relative2);
|
|
9364
9481
|
let stat;
|
|
9365
9482
|
try {
|
|
9366
|
-
stat = await
|
|
9483
|
+
stat = await fs7.lstat(file);
|
|
9367
9484
|
} catch (cause) {
|
|
9368
9485
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
9369
9486
|
}
|
|
9370
9487
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9371
9488
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
9372
|
-
return
|
|
9489
|
+
return fs7.readFile(file);
|
|
9373
9490
|
}
|
|
9374
9491
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
9375
9492
|
const parts = relative2.split("/").filter(Boolean);
|
|
9376
9493
|
let current = project;
|
|
9377
9494
|
for (const part of parts) {
|
|
9378
|
-
current =
|
|
9379
|
-
const stat = await
|
|
9495
|
+
current = path11.join(current, part);
|
|
9496
|
+
const stat = await fs7.lstat(current).catch(() => void 0);
|
|
9380
9497
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9381
9498
|
if (!stat) break;
|
|
9382
9499
|
}
|
|
9383
9500
|
}
|
|
9384
9501
|
async function realProject(requested) {
|
|
9385
|
-
const absolute =
|
|
9502
|
+
const absolute = path11.resolve(requested);
|
|
9386
9503
|
let project;
|
|
9387
9504
|
try {
|
|
9388
|
-
project = await
|
|
9505
|
+
project = await fs7.realpath(absolute);
|
|
9389
9506
|
} catch (cause) {
|
|
9390
9507
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
9391
9508
|
}
|
|
9392
|
-
const stat = await
|
|
9509
|
+
const stat = await fs7.stat(project);
|
|
9393
9510
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
9394
9511
|
return project;
|
|
9395
9512
|
}
|
|
9396
9513
|
function safeRelative(reference, label) {
|
|
9397
|
-
if (!reference ||
|
|
9514
|
+
if (!reference || path11.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
9398
9515
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
9399
9516
|
}
|
|
9400
|
-
const normalized =
|
|
9517
|
+
const normalized = path11.normalize(reference).split(path11.sep).join("/");
|
|
9401
9518
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
9402
9519
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
9403
9520
|
}
|
|
@@ -9461,7 +9578,7 @@ init_exit();
|
|
|
9461
9578
|
import {
|
|
9462
9579
|
HcmClient as HcmClient24,
|
|
9463
9580
|
adminResetPassword,
|
|
9464
|
-
formatObject as
|
|
9581
|
+
formatObject as formatObject25,
|
|
9465
9582
|
fromAxiosError as fromAxiosError20,
|
|
9466
9583
|
CliError as CliError21,
|
|
9467
9584
|
CliErrorCode as CliErrorCode20
|
|
@@ -9495,7 +9612,7 @@ async function userResetPasswordCommand(args) {
|
|
|
9495
9612
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
9496
9613
|
const client3 = HcmClient24.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
9497
9614
|
const result = await adminResetPassword(client3.raw(), request);
|
|
9498
|
-
process.stdout.write(
|
|
9615
|
+
process.stdout.write(formatObject25(result, { format: args.output ?? "json" }) + "\n");
|
|
9499
9616
|
} catch (cause) {
|
|
9500
9617
|
const err = cause;
|
|
9501
9618
|
if (err?.isAxiosError) exitWithError(fromAxiosError20(err, args.env));
|
|
@@ -9519,7 +9636,7 @@ init_exit();
|
|
|
9519
9636
|
init_auth_guard();
|
|
9520
9637
|
import {
|
|
9521
9638
|
HcmClient as HcmClient25,
|
|
9522
|
-
formatObject as
|
|
9639
|
+
formatObject as formatObject26,
|
|
9523
9640
|
fromAxiosError as fromAxiosError21
|
|
9524
9641
|
} from "@hcmai/sdk";
|
|
9525
9642
|
async function modelsCommand(keyword, args) {
|
|
@@ -9530,7 +9647,7 @@ async function modelsCommand(keyword, args) {
|
|
|
9530
9647
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
9531
9648
|
const fmt = args.output ?? "table";
|
|
9532
9649
|
if (fmt !== "table") {
|
|
9533
|
-
process.stdout.write(
|
|
9650
|
+
process.stdout.write(formatObject26({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
9534
9651
|
process.exit(0);
|
|
9535
9652
|
}
|
|
9536
9653
|
if (rows.length === 0) {
|
|
@@ -9666,6 +9783,7 @@ delivery.command("triage").description(
|
|
|
9666
9783
|
"--recon <dir>",
|
|
9667
9784
|
"\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"
|
|
9668
9785
|
).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));
|
|
9786
|
+
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));
|
|
9669
9787
|
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));
|
|
9670
9788
|
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));
|
|
9671
9789
|
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(
|