@hcmai/cli 0.5.0 → 0.6.0
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 +571 -454
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +3 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -121,9 +121,9 @@ __export(attachment_args_exports, {
|
|
|
121
121
|
extractInlineFilePaths: () => extractInlineFilePaths,
|
|
122
122
|
isBareFilePath: () => isBareFilePath
|
|
123
123
|
});
|
|
124
|
-
import * as
|
|
124
|
+
import * as fs3 from "fs";
|
|
125
125
|
import * as os from "os";
|
|
126
|
-
import * as
|
|
126
|
+
import * as path2 from "path";
|
|
127
127
|
function extractAtFileTokens(text) {
|
|
128
128
|
const paths = [];
|
|
129
129
|
const re = /@(?:"([^"]+)"|'([^']+)'|(\S+))/g;
|
|
@@ -159,11 +159,11 @@ function isBareFilePath(text) {
|
|
|
159
159
|
return isExistingFile(abs) ? abs : null;
|
|
160
160
|
}
|
|
161
161
|
function expandHome(p) {
|
|
162
|
-
return p.startsWith("~") ?
|
|
162
|
+
return p.startsWith("~") ? path2.join(os.homedir(), p.slice(1)) : path2.resolve(p);
|
|
163
163
|
}
|
|
164
164
|
function isExistingFile(p) {
|
|
165
165
|
try {
|
|
166
|
-
return
|
|
166
|
+
return fs3.statSync(p).isFile();
|
|
167
167
|
} catch {
|
|
168
168
|
return false;
|
|
169
169
|
}
|
|
@@ -532,8 +532,8 @@ var init_TerminalRenderer = __esm({
|
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
534
|
/** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
|
|
535
|
-
originLine(
|
|
536
|
-
const segs =
|
|
535
|
+
originLine(path19) {
|
|
536
|
+
const segs = path19.split(".").filter(Boolean);
|
|
537
537
|
if (segs.length < 2) return "";
|
|
538
538
|
const names = segs.map((k) => agentDisplayName(k));
|
|
539
539
|
return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
|
|
@@ -1312,7 +1312,7 @@ var init_types = __esm({
|
|
|
1312
1312
|
|
|
1313
1313
|
// src/repl/App.tsx
|
|
1314
1314
|
import { useCallback, useEffect as useEffect2, useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
1315
|
-
import * as
|
|
1315
|
+
import * as fs4 from "fs/promises";
|
|
1316
1316
|
import { Box as Box3, Static, Text as Text3, useApp, useInput as useInput2 } from "ink";
|
|
1317
1317
|
import TextInput from "ink-text-input";
|
|
1318
1318
|
import SelectInput from "ink-select-input";
|
|
@@ -1359,7 +1359,7 @@ function ReplApp(props) {
|
|
|
1359
1359
|
const histIdxRef = useRef2(-1);
|
|
1360
1360
|
const draftRef = useRef2("");
|
|
1361
1361
|
useEffect2(() => {
|
|
1362
|
-
void
|
|
1362
|
+
void fs4.readFile(replHistoryFile(props.env), "utf-8").then((c) => {
|
|
1363
1363
|
historyRef.current = c.split("\n").filter(Boolean);
|
|
1364
1364
|
}).catch(() => {
|
|
1365
1365
|
});
|
|
@@ -1546,7 +1546,7 @@ function ReplApp(props) {
|
|
|
1546
1546
|
}
|
|
1547
1547
|
historyRef.current.push(line);
|
|
1548
1548
|
histIdxRef.current = -1;
|
|
1549
|
-
void
|
|
1549
|
+
void fs4.appendFile(replHistoryFile(props.env), line.replace(/\n/g, " ") + "\n").catch(() => {
|
|
1550
1550
|
});
|
|
1551
1551
|
void (async () => {
|
|
1552
1552
|
const at = extractAtFileTokens(line);
|
|
@@ -1715,8 +1715,8 @@ function agentLabel(agentId) {
|
|
|
1715
1715
|
if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
|
|
1716
1716
|
return agentDisplayName(agentId);
|
|
1717
1717
|
}
|
|
1718
|
-
function originLine(
|
|
1719
|
-
const segs = (
|
|
1718
|
+
function originLine(path19) {
|
|
1719
|
+
const segs = (path19 ?? "").split(".").filter(Boolean);
|
|
1720
1720
|
if (segs.length < 2) return null;
|
|
1721
1721
|
return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
|
|
1722
1722
|
}
|
|
@@ -2895,8 +2895,8 @@ import {
|
|
|
2895
2895
|
HcmClient as HcmClient2,
|
|
2896
2896
|
formatObject,
|
|
2897
2897
|
fromAxiosError as fromAxiosError2,
|
|
2898
|
-
CliError as
|
|
2899
|
-
CliErrorCode as
|
|
2898
|
+
CliError as CliError9,
|
|
2899
|
+
CliErrorCode as CliErrorCode8
|
|
2900
2900
|
} from "@hcmai/sdk";
|
|
2901
2901
|
|
|
2902
2902
|
// src/utils/json-input.ts
|
|
@@ -2951,19 +2951,106 @@ async function readJsonObjectInput(options) {
|
|
|
2951
2951
|
return parsed;
|
|
2952
2952
|
}
|
|
2953
2953
|
|
|
2954
|
+
// src/artifact.ts
|
|
2955
|
+
import { createHash } from "crypto";
|
|
2956
|
+
import { CliError as CliError8, CliErrorCode as CliErrorCode7 } from "@hcmai/sdk";
|
|
2957
|
+
import { promises as fs2 } from "fs";
|
|
2958
|
+
import path from "path";
|
|
2959
|
+
var MAX_ARTIFACT_BYTES = 10 * 1024 * 1024;
|
|
2960
|
+
var ARTIFACT_ENCODING_BASE64 = "base64";
|
|
2961
|
+
var SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
2962
|
+
var isStr = (v) => typeof v === "string";
|
|
2963
|
+
function parseArtifactEnvelope(data) {
|
|
2964
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
2965
|
+
return { ok: false, reason: "\u54CD\u5E94\u4F53\u4E0D\u662F\u5BF9\u8C61" };
|
|
2966
|
+
}
|
|
2967
|
+
const o = data;
|
|
2968
|
+
const missing = ["fileName", "mediaType", "encoding", "content", "sizeBytes", "sha256", "capabilityVersion", "language"].filter(
|
|
2969
|
+
(k) => !(k in o)
|
|
2970
|
+
);
|
|
2971
|
+
if (missing.length) return { ok: false, reason: `\u4E0D\u662F\u6807\u51C6\u5236\u54C1\u4FE1\u5C01\uFF0C\u7F3A\u5B57\u6BB5\uFF1A${missing.join(", ")}` };
|
|
2972
|
+
if (!isStr(o.fileName) || !o.fileName.trim()) return { ok: false, reason: "fileName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32" };
|
|
2973
|
+
if (!isStr(o.mediaType) || !o.mediaType.trim()) return { ok: false, reason: "mediaType \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32" };
|
|
2974
|
+
if (o.encoding !== ARTIFACT_ENCODING_BASE64) {
|
|
2975
|
+
return { ok: false, reason: `encoding \u53EA\u652F\u6301 ${ARTIFACT_ENCODING_BASE64}\uFF0C\u6536\u5230 ${JSON.stringify(o.encoding)}` };
|
|
2976
|
+
}
|
|
2977
|
+
if (!isStr(o.content)) return { ok: false, reason: "content \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" };
|
|
2978
|
+
if (typeof o.sizeBytes !== "number" || !Number.isInteger(o.sizeBytes) || o.sizeBytes < 0) {
|
|
2979
|
+
return { ok: false, reason: `sizeBytes \u5FC5\u987B\u662F\u975E\u8D1F\u6574\u6570\uFF0C\u6536\u5230 ${JSON.stringify(o.sizeBytes)}` };
|
|
2980
|
+
}
|
|
2981
|
+
if (!isStr(o.sha256) || !SHA256_HEX.test(o.sha256)) return { ok: false, reason: "sha256 \u5FC5\u987B\u662F 64 \u4F4D\u5C0F\u5199 hex" };
|
|
2982
|
+
if (!isStr(o.capabilityVersion)) return { ok: false, reason: "capabilityVersion \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u65E0\u7248\u672C\u65F6\u4E3A\u7A7A\u4E32\uFF0C\u4E0D\u662F null\uFF09" };
|
|
2983
|
+
if (!isStr(o.language) || !o.language.trim()) {
|
|
2984
|
+
return { ok: false, reason: "language \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u5236\u54C1\u8868\u5934\u968F\u8BED\u8A00\u53D8\uFF0C\u5FC5\u987B\u81EA\u9648\uFF09" };
|
|
2985
|
+
}
|
|
2986
|
+
return { ok: true, artifact: o };
|
|
2987
|
+
}
|
|
2988
|
+
var fail = (message, nextStep) => new CliError8({ code: CliErrorCode7.INVALID_ARGUMENT, message, context: { nextStep } });
|
|
2989
|
+
async function writeArtifact(artifact, target, opts = {}) {
|
|
2990
|
+
const abs = path.resolve(target);
|
|
2991
|
+
const stat = await fs2.lstat(abs).catch(() => null);
|
|
2992
|
+
if (stat) {
|
|
2993
|
+
if (stat.isSymbolicLink()) {
|
|
2994
|
+
throw fail(`\u76EE\u6807\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A${abs}`, "\u6362\u4E00\u4E2A\u771F\u5B9E\u8DEF\u5F84\u3002\u8DDF\u7740\u7B26\u53F7\u94FE\u63A5\u5199\u4F1A\u843D\u5230\u94FE\u63A5\u6307\u5411\u7684\u5730\u65B9\uFF0C\u90A3\u4E0D\u662F\u4F60\u5728\u547D\u4EE4\u884C\u91CC\u6307\u5B9A\u7684\u4F4D\u7F6E\u3002");
|
|
2995
|
+
}
|
|
2996
|
+
if (stat.isDirectory()) {
|
|
2997
|
+
throw fail(`\u76EE\u6807\u662F\u76EE\u5F55\uFF0C\u4E0D\u662F\u6587\u4EF6\uFF1A${abs}`, "--artifact-output \u8981\u7ED9**\u6587\u4EF6**\u8DEF\u5F84\uFF08\u670D\u52A1\u7AEF\u7ED9\u7684 fileName \u4E0D\u4F1A\u88AB\u62FC\u8FDB\u53BB\uFF0C\u90A3\u6837\u4F1A\u5E26\u6765\u8DEF\u5F84\u7A7F\u8D8A\uFF09\u3002");
|
|
2998
|
+
}
|
|
2999
|
+
if (!opts.force) {
|
|
3000
|
+
throw fail(`\u76EE\u6807\u5DF2\u5B58\u5728\uFF1A${abs}`, "\u6362\u4E2A\u8DEF\u5F84\uFF0C\u6216\u663E\u5F0F\u52A0 --artifact-force \u8986\u76D6\u3002\u9ED8\u8BA4\u4E0D\u8986\u76D6\uFF0C\u514D\u5F97\u628A\u4E0A\u4E00\u8F6E\u7684\u8BC1\u636E\u6084\u6084\u6362\u6389\u3002");
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
let bytes;
|
|
3004
|
+
try {
|
|
3005
|
+
bytes = Buffer.from(artifact.content, "base64");
|
|
3006
|
+
} catch {
|
|
3007
|
+
throw fail("content \u4E0D\u662F\u5408\u6CD5 base64", "\u8FD9\u4E0D\u662F\u4E00\u4EFD\u53EF\u7528\u7684\u5236\u54C1\uFF0C\u68C0\u67E5\u670D\u52A1\u7AEF\u54CD\u5E94\uFF1B\u4E0D\u8981\u624B\u5DE5\u6539\u9020\u5B83\u3002");
|
|
3008
|
+
}
|
|
3009
|
+
if (bytes.byteLength > MAX_ARTIFACT_BYTES) {
|
|
3010
|
+
throw fail(`\u5236\u54C1 ${bytes.byteLength} \u5B57\u8282\uFF0C\u8D85\u8FC7\u4E0A\u9650 ${MAX_ARTIFACT_BYTES}`, "\u8FD9\u4E00\u6863\u53EA\u8D70\u4E0D\u843D\u5E93\u7684\u5C0F\u5236\u54C1\uFF1B\u66F4\u5927\u7684\u4EA7\u7269\u8BF7\u8D70\u4F1A\u5EFA Document \u7684\u90A3\u6761\u5165\u53E3\u3002");
|
|
3011
|
+
}
|
|
3012
|
+
if (bytes.byteLength !== artifact.sizeBytes) {
|
|
3013
|
+
throw fail(`\u5B57\u8282\u6570\u5BF9\u4E0D\u4E0A\uFF1A\u4FE1\u5C01\u8BF4 ${artifact.sizeBytes}\uFF0C\u89E3\u7801\u51FA ${bytes.byteLength}`, "\u54CD\u5E94\u5728\u4F20\u8F93\u4E2D\u88AB\u6539\u8FC7\u6216\u670D\u52A1\u7AEF\u7B97\u9519\u4E86\u3002\u4E0D\u8981\u843D\u76D8\u2014\u2014\u843D\u4E0B\u53BB\u7684\u4F1A\u662F\u4E00\u4EFD\u770B\u7740\u6B63\u5E38\u7684\u574F\u6587\u4EF6\u3002");
|
|
3014
|
+
}
|
|
3015
|
+
const digest = createHash("sha256").update(bytes).digest("hex");
|
|
3016
|
+
if (digest !== artifact.sha256) {
|
|
3017
|
+
throw fail(`SHA-256 \u5BF9\u4E0D\u4E0A\uFF1A\u4FE1\u5C01\u8BF4 ${artifact.sha256}\uFF0C\u5B9E\u9645 ${digest}`, "\u540C\u4E0A\uFF1A\u5185\u5BB9\u4E0E\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u8FD9\u4EFD\u5236\u54C1\u4E0D\u53EF\u4FE1\uFF0C\u4E0D\u843D\u76D8\u3002");
|
|
3018
|
+
}
|
|
3019
|
+
const dir = path.dirname(abs);
|
|
3020
|
+
await fs2.mkdir(dir, { recursive: true });
|
|
3021
|
+
const tmp = path.join(dir, `.tmp-artifact-${process.pid}-${Date.now()}`);
|
|
3022
|
+
try {
|
|
3023
|
+
await fs2.writeFile(tmp, bytes, { mode: 384, flag: "wx" });
|
|
3024
|
+
await fs2.rename(tmp, abs);
|
|
3025
|
+
} catch (e) {
|
|
3026
|
+
await fs2.rm(tmp, { force: true }).catch(() => {
|
|
3027
|
+
});
|
|
3028
|
+
throw fail(`\u5199\u5165\u5931\u8D25\uFF1A${e.message}`, "\u68C0\u67E5\u76EE\u5F55\u6743\u9650\u4E0E\u78C1\u76D8\u7A7A\u95F4\u3002\u4E34\u65F6\u6587\u4EF6\u5DF2\u6E05\u6389\uFF0C\u76EE\u6807\u8DEF\u5F84\u4E0A\u4E0D\u4F1A\u7559\u4E0B\u534A\u4EFD\u6587\u4EF6\u3002");
|
|
3029
|
+
}
|
|
3030
|
+
return {
|
|
3031
|
+
path: abs,
|
|
3032
|
+
sizeBytes: artifact.sizeBytes,
|
|
3033
|
+
sha256: artifact.sha256,
|
|
3034
|
+
fileName: artifact.fileName,
|
|
3035
|
+
mediaType: artifact.mediaType,
|
|
3036
|
+
capabilityVersion: artifact.capabilityVersion,
|
|
3037
|
+
language: artifact.language
|
|
3038
|
+
};
|
|
3039
|
+
}
|
|
3040
|
+
|
|
2954
3041
|
// src/commands/action.ts
|
|
2955
3042
|
async function actionCommand(spec, args) {
|
|
2956
3043
|
try {
|
|
2957
3044
|
const [model, action] = spec.split(".");
|
|
2958
3045
|
if (!model || !action) {
|
|
2959
|
-
throw new
|
|
2960
|
-
code:
|
|
3046
|
+
throw new CliError9({
|
|
3047
|
+
code: CliErrorCode8.INVALID_ARGUMENT,
|
|
2961
3048
|
message: "expected <Model>.<Action> (e.g. Employee.regularize)"
|
|
2962
3049
|
});
|
|
2963
3050
|
}
|
|
2964
3051
|
if (args.id && args.ids) {
|
|
2965
|
-
throw new
|
|
2966
|
-
code:
|
|
3052
|
+
throw new CliError9({
|
|
3053
|
+
code: CliErrorCode8.INVALID_ARGUMENT,
|
|
2967
3054
|
message: "--id and --ids are mutually exclusive"
|
|
2968
3055
|
});
|
|
2969
3056
|
}
|
|
@@ -2995,6 +3082,10 @@ async function actionCommand(spec, args) {
|
|
|
2995
3082
|
}
|
|
2996
3083
|
const result = await client3.action(model, action, input);
|
|
2997
3084
|
const fmt = args.output ?? "json";
|
|
3085
|
+
if (args.artifactOutput) {
|
|
3086
|
+
await emitArtifact(result, args.artifactOutput, { force: args.artifactForce }, fmt);
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
2998
3089
|
printActionResult(result, fmt);
|
|
2999
3090
|
} catch (e) {
|
|
3000
3091
|
const err = e;
|
|
@@ -3004,6 +3095,29 @@ async function actionCommand(spec, args) {
|
|
|
3004
3095
|
exitWithError(e);
|
|
3005
3096
|
}
|
|
3006
3097
|
}
|
|
3098
|
+
async function emitArtifact(result, target, opts, fmt) {
|
|
3099
|
+
const parsed = parseArtifactEnvelope(result?.data ?? result);
|
|
3100
|
+
if (!parsed.ok) {
|
|
3101
|
+
throw new CliError9({
|
|
3102
|
+
code: CliErrorCode8.INVALID_ARGUMENT,
|
|
3103
|
+
message: `--artifact-output \u53EA\u63A5\u53D7\u6807\u51C6\u53EA\u8BFB\u5236\u54C1\u54CD\u5E94\uFF1A${parsed.reason}`,
|
|
3104
|
+
context: {
|
|
3105
|
+
nextStep: "\u786E\u8BA4\u8FD9\u4E2A Action \u5728\u76EE\u6807 Core \u4E0A\u8FD4\u56DE ActionArtifact\uFF08fileName / mediaType / encoding / content / sizeBytes / sha256 / capabilityVersion / language \u516B\u4E2A\u952E\uFF09\u3002\u82E5\u76EE\u6807 Core \u8F83\u65E7\u3001\u8FD8\u6CA1\u6709\u8FD9\u6761\u53EA\u8BFB\u5165\u53E3\uFF0C\u8BF7\u5347\u7EA7 Core\u2014\u2014\u4E0D\u8981\u6539\u7528\u4F1A\u521B\u5EFA Document \u7684\u5199\u5165\u53E3\u6765\u7ED5\u8FC7\u3002"
|
|
3106
|
+
}
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
const written = await writeArtifact(parsed.artifact, target, opts);
|
|
3110
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
3111
|
+
process.stdout.write(formatObject({ artifact: written }, { format: fmt }) + "\n");
|
|
3112
|
+
} else {
|
|
3113
|
+
process.stdout.write(
|
|
3114
|
+
`\u2705 \u5236\u54C1\u5DF2\u843D\u76D8\uFF1A${written.path}
|
|
3115
|
+
${written.sizeBytes} \u5B57\u8282 \xB7 sha256 ${written.sha256.slice(0, 12)}\u2026 \xB7 ${written.mediaType} \xB7 \u8BED\u8A00 ${written.language}
|
|
3116
|
+
`
|
|
3117
|
+
);
|
|
3118
|
+
}
|
|
3119
|
+
process.exitCode = 0;
|
|
3120
|
+
}
|
|
3007
3121
|
function printActionResult(result, fmt) {
|
|
3008
3122
|
if (fmt !== "json" && result.taskId) {
|
|
3009
3123
|
process.stdout.write(
|
|
@@ -3019,16 +3133,16 @@ function printActionResult(result, fmt) {
|
|
|
3019
3133
|
function normalizeMethod(value) {
|
|
3020
3134
|
const raw = (value ?? "POST").toUpperCase();
|
|
3021
3135
|
if (raw === "GET" || raw === "POST" || raw === "PUT" || raw === "DELETE") return raw;
|
|
3022
|
-
throw new
|
|
3023
|
-
code:
|
|
3136
|
+
throw new CliError9({
|
|
3137
|
+
code: CliErrorCode8.INVALID_ARGUMENT,
|
|
3024
3138
|
message: `--method \u53D6\u503C GET | POST | PUT | DELETE\uFF0C\u6536\u5230 "${value}"`
|
|
3025
3139
|
});
|
|
3026
3140
|
}
|
|
3027
3141
|
function normalizeScope(value) {
|
|
3028
3142
|
if (value === void 0) return void 0;
|
|
3029
3143
|
if (value === "class" || value === "object") return value;
|
|
3030
|
-
throw new
|
|
3031
|
-
code:
|
|
3144
|
+
throw new CliError9({
|
|
3145
|
+
code: CliErrorCode8.INVALID_ARGUMENT,
|
|
3032
3146
|
message: `--scope \u53D6\u503C class | object\uFF0C\u6536\u5230 "${value}"`
|
|
3033
3147
|
});
|
|
3034
3148
|
}
|
|
@@ -3080,13 +3194,13 @@ import {
|
|
|
3080
3194
|
HcmClient as HcmClient4,
|
|
3081
3195
|
formatObject as formatObject3,
|
|
3082
3196
|
fromAxiosError as fromAxiosError4,
|
|
3083
|
-
CliError as
|
|
3084
|
-
CliErrorCode as
|
|
3197
|
+
CliError as CliError10,
|
|
3198
|
+
CliErrorCode as CliErrorCode9
|
|
3085
3199
|
} from "@hcmai/sdk";
|
|
3086
3200
|
async function updateCommand(model, args) {
|
|
3087
3201
|
try {
|
|
3088
3202
|
if (!args.id) {
|
|
3089
|
-
throw new
|
|
3203
|
+
throw new CliError10({ code: CliErrorCode9.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
|
|
3090
3204
|
}
|
|
3091
3205
|
const data = await readJsonObjectInput({
|
|
3092
3206
|
inline: args.data,
|
|
@@ -3119,15 +3233,15 @@ import {
|
|
|
3119
3233
|
patchSettingDomain,
|
|
3120
3234
|
resetSettingItem,
|
|
3121
3235
|
parseSettingAssignment,
|
|
3122
|
-
CliError as
|
|
3123
|
-
CliErrorCode as
|
|
3236
|
+
CliError as CliError11,
|
|
3237
|
+
CliErrorCode as CliErrorCode10
|
|
3124
3238
|
} from "@hcmai/sdk";
|
|
3125
3239
|
init_exit();
|
|
3126
3240
|
init_auth_guard();
|
|
3127
3241
|
async function client(args) {
|
|
3128
3242
|
return HcmClient5.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
3129
3243
|
}
|
|
3130
|
-
function
|
|
3244
|
+
function fail2(e, args) {
|
|
3131
3245
|
const err = e;
|
|
3132
3246
|
if (err?.response?.status === 404) {
|
|
3133
3247
|
exitWithError(new Error("\u6CA1\u6709\u8FD9\u4E2A\u53C2\u6570\u57DF \u2014\u2014 \u7528 `hcm setting get <\u57DF>` \u770B\u73B0\u6709\u57DF\uFF0C\u5E38\u89C1\u6709 security / feature / integration"));
|
|
@@ -3156,15 +3270,15 @@ async function settingGetCommand(domain, args) {
|
|
|
3156
3270
|
process.exitCode = 0;
|
|
3157
3271
|
return;
|
|
3158
3272
|
} catch (e) {
|
|
3159
|
-
|
|
3273
|
+
fail2(e, args);
|
|
3160
3274
|
}
|
|
3161
3275
|
}
|
|
3162
3276
|
async function settingSetCommand(domain, args) {
|
|
3163
3277
|
try {
|
|
3164
3278
|
const raw = args.set ?? [];
|
|
3165
3279
|
if (raw.length === 0) {
|
|
3166
|
-
throw new
|
|
3167
|
-
code:
|
|
3280
|
+
throw new CliError11({
|
|
3281
|
+
code: CliErrorCode10.MISSING_FLAG,
|
|
3168
3282
|
message: "\u81F3\u5C11\u8981\u4E00\u4E2A --set namespace.key=value\uFF0C\u4F8B\u5982 --set security.password.passwordPolicy=complex"
|
|
3169
3283
|
});
|
|
3170
3284
|
}
|
|
@@ -3172,7 +3286,7 @@ async function settingSetCommand(domain, args) {
|
|
|
3172
3286
|
try {
|
|
3173
3287
|
items = raw.map(parseSettingAssignment);
|
|
3174
3288
|
} catch (e) {
|
|
3175
|
-
throw new
|
|
3289
|
+
throw new CliError11({ code: CliErrorCode10.INVALID_ARGUMENT, message: e.message });
|
|
3176
3290
|
}
|
|
3177
3291
|
if (args.dryRun) {
|
|
3178
3292
|
process.stdout.write(`[dry-run] \u5C06\u5728\u57DF ${domain} \u5199\u5165 ${items.length} \u9879\uFF0C\u672A\u5B9E\u9645\u5199\u5165\uFF1A
|
|
@@ -3191,7 +3305,7 @@ async function settingSetCommand(domain, args) {
|
|
|
3191
3305
|
process.exitCode = 0;
|
|
3192
3306
|
return;
|
|
3193
3307
|
} catch (e) {
|
|
3194
|
-
|
|
3308
|
+
fail2(e, args);
|
|
3195
3309
|
}
|
|
3196
3310
|
}
|
|
3197
3311
|
async function settingResetCommand(domain, namespace, key2, args) {
|
|
@@ -3213,7 +3327,7 @@ async function settingResetCommand(domain, namespace, key2, args) {
|
|
|
3213
3327
|
process.exitCode = 0;
|
|
3214
3328
|
return;
|
|
3215
3329
|
} catch (e) {
|
|
3216
|
-
|
|
3330
|
+
fail2(e, args);
|
|
3217
3331
|
}
|
|
3218
3332
|
}
|
|
3219
3333
|
|
|
@@ -3226,8 +3340,8 @@ import {
|
|
|
3226
3340
|
loadEnv as loadEnv4,
|
|
3227
3341
|
loadGlobalConfig as loadGlobalConfig5,
|
|
3228
3342
|
resolveActiveEnv as resolveActiveEnv2,
|
|
3229
|
-
CliError as
|
|
3230
|
-
CliErrorCode as
|
|
3343
|
+
CliError as CliError12,
|
|
3344
|
+
CliErrorCode as CliErrorCode11
|
|
3231
3345
|
} from "@hcmai/sdk";
|
|
3232
3346
|
async function versionCommand(args) {
|
|
3233
3347
|
try {
|
|
@@ -3236,8 +3350,8 @@ async function versionCommand(args) {
|
|
|
3236
3350
|
const g = await loadGlobalConfig5();
|
|
3237
3351
|
const env3 = await loadEnv4(resolveActiveEnv2({ envFlag: args.env }, process.env, g)).catch(() => null);
|
|
3238
3352
|
if (!env3?.endpoint) {
|
|
3239
|
-
throw new
|
|
3240
|
-
code:
|
|
3353
|
+
throw new CliError12({
|
|
3354
|
+
code: CliErrorCode11.MISSING_FLAG,
|
|
3241
3355
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
|
|
3242
3356
|
});
|
|
3243
3357
|
}
|
|
@@ -3330,15 +3444,15 @@ async function upgradeCommand(args) {
|
|
|
3330
3444
|
init_auth_guard();
|
|
3331
3445
|
init_exit();
|
|
3332
3446
|
import { spawn } from "child_process";
|
|
3333
|
-
import { CliError as
|
|
3447
|
+
import { CliError as CliError13, CliErrorCode as CliErrorCode12, fromAxiosError as fromAxiosError7, HcmClient as HcmClient6, loadEnv as loadEnv5 } from "@hcmai/sdk";
|
|
3334
3448
|
var BROWSER_TICKET_PATH = "/api/auth/browser-ticket";
|
|
3335
3449
|
var SSO_CALLBACK_PATH = "/sso/callback";
|
|
3336
3450
|
function normalizeTarget(target) {
|
|
3337
3451
|
const raw = (target ?? "").trim();
|
|
3338
3452
|
if (!raw) return "/";
|
|
3339
3453
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) {
|
|
3340
|
-
throw new
|
|
3341
|
-
code:
|
|
3454
|
+
throw new CliError13({
|
|
3455
|
+
code: CliErrorCode12.INVALID_ARGUMENT,
|
|
3342
3456
|
message: `\u53EA\u6536\u7AD9\u5185\u8DEF\u5F84\uFF08\u5982 /dashboard/<id>\uFF09\uFF0C\u4E0D\u6536\u5B8C\u6574 URL\uFF1A${raw}`
|
|
3343
3457
|
});
|
|
3344
3458
|
}
|
|
@@ -3362,21 +3476,21 @@ function launchBrowser(url, platform = process.platform) {
|
|
|
3362
3476
|
child.unref();
|
|
3363
3477
|
}
|
|
3364
3478
|
async function runOpen(target, args, deps) {
|
|
3365
|
-
const
|
|
3479
|
+
const path19 = normalizeTarget(target);
|
|
3366
3480
|
if (!deps.frontend?.trim()) {
|
|
3367
|
-
throw new
|
|
3368
|
-
code:
|
|
3481
|
+
throw new CliError13({
|
|
3482
|
+
code: CliErrorCode12.INVALID_ARGUMENT,
|
|
3369
3483
|
message: `env '${args.envName}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002\u5148\u8DD1\uFF1Ahcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${args.envName}`
|
|
3370
3484
|
});
|
|
3371
3485
|
}
|
|
3372
3486
|
const { ticket, expiresIn } = await deps.mintTicket();
|
|
3373
|
-
const url = buildBrowserLoginUrl(deps.frontend, ticket,
|
|
3487
|
+
const url = buildBrowserLoginUrl(deps.frontend, ticket, path19);
|
|
3374
3488
|
if (args.printUrl) {
|
|
3375
3489
|
deps.write(`${url}
|
|
3376
3490
|
`);
|
|
3377
3491
|
} else {
|
|
3378
3492
|
deps.launch(url);
|
|
3379
|
-
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${
|
|
3493
|
+
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path19}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
|
|
3380
3494
|
`);
|
|
3381
3495
|
}
|
|
3382
3496
|
return { url, expiresIn };
|
|
@@ -3399,8 +3513,8 @@ async function openCommand(target, args) {
|
|
|
3399
3513
|
} catch (e) {
|
|
3400
3514
|
const err = e;
|
|
3401
3515
|
if (err?.isAxiosError && err.response?.status === 404) {
|
|
3402
|
-
throw new
|
|
3403
|
-
code:
|
|
3516
|
+
throw new CliError13({
|
|
3517
|
+
code: CliErrorCode12.INVALID_ARGUMENT,
|
|
3404
3518
|
message: `\u540E\u7AEF\u6CA1\u6709 ${BROWSER_TICKET_PATH}\uFF08\u9700\u8981\u542B\u6D4F\u89C8\u5668\u4F1A\u8BDD\u7968\u636E\u7684\u540E\u7AEF\u7248\u672C\uFF09\uFF0C\u5347\u7EA7\u540E\u7AEF\u540E\u518D\u8BD5\u3002\u672C\u547D\u4EE4\u4E0D\u4F1A\u628A\u4F1A\u8BDD token \u62FC\u8FDB URL \u515C\u5E95\u3002`
|
|
3405
3519
|
});
|
|
3406
3520
|
}
|
|
@@ -3408,8 +3522,8 @@ async function openCommand(target, args) {
|
|
|
3408
3522
|
throw e;
|
|
3409
3523
|
}
|
|
3410
3524
|
if (typeof data.ticket !== "string" || !data.ticket) {
|
|
3411
|
-
throw new
|
|
3412
|
-
code:
|
|
3525
|
+
throw new CliError13({
|
|
3526
|
+
code: CliErrorCode12.INVALID_ARGUMENT,
|
|
3413
3527
|
message: "\u94F8\u7968\u54CD\u5E94\u91CC\u6CA1\u6709 ticket \u2014\u2014 \u540E\u7AEF\u7248\u672C\u4E0E\u672C CLI \u7684\u5951\u7EA6\u5BF9\u4E0D\u4E0A"
|
|
3414
3528
|
});
|
|
3415
3529
|
}
|
|
@@ -3436,13 +3550,13 @@ import {
|
|
|
3436
3550
|
HcmClient as HcmClient7,
|
|
3437
3551
|
formatObject as formatObject6,
|
|
3438
3552
|
fromAxiosError as fromAxiosError8,
|
|
3439
|
-
CliError as
|
|
3440
|
-
CliErrorCode as
|
|
3553
|
+
CliError as CliError14,
|
|
3554
|
+
CliErrorCode as CliErrorCode13
|
|
3441
3555
|
} from "@hcmai/sdk";
|
|
3442
3556
|
async function deleteCommand(model, args) {
|
|
3443
3557
|
try {
|
|
3444
3558
|
if (!args.id) {
|
|
3445
|
-
throw new
|
|
3559
|
+
throw new CliError14({ code: CliErrorCode13.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
|
|
3446
3560
|
}
|
|
3447
3561
|
const client3 = HcmClient7.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
3448
3562
|
const res = await client3.remove(model, args.id);
|
|
@@ -3470,8 +3584,8 @@ import {
|
|
|
3470
3584
|
formatObject as formatObject7,
|
|
3471
3585
|
fromAxiosError as fromAxiosError9
|
|
3472
3586
|
} from "@hcmai/sdk";
|
|
3473
|
-
function collectYmlFiles(
|
|
3474
|
-
if (statSync(
|
|
3587
|
+
function collectYmlFiles(path19) {
|
|
3588
|
+
if (statSync(path19).isFile()) return [path19];
|
|
3475
3589
|
const out = [];
|
|
3476
3590
|
const walk = (dir) => {
|
|
3477
3591
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3480,7 +3594,7 @@ function collectYmlFiles(path18) {
|
|
|
3480
3594
|
else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
|
|
3481
3595
|
}
|
|
3482
3596
|
};
|
|
3483
|
-
walk(
|
|
3597
|
+
walk(path19);
|
|
3484
3598
|
return out.sort();
|
|
3485
3599
|
}
|
|
3486
3600
|
var DRY_RUN_CLIENT = {
|
|
@@ -3488,9 +3602,9 @@ var DRY_RUN_CLIENT = {
|
|
|
3488
3602
|
create: async () => ({ id: "" }),
|
|
3489
3603
|
update: async () => ({})
|
|
3490
3604
|
};
|
|
3491
|
-
async function importCommand(
|
|
3605
|
+
async function importCommand(path19, args) {
|
|
3492
3606
|
try {
|
|
3493
|
-
const files = collectYmlFiles(
|
|
3607
|
+
const files = collectYmlFiles(path19);
|
|
3494
3608
|
const fixtures = files.map(
|
|
3495
3609
|
(f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
|
|
3496
3610
|
);
|
|
@@ -3601,8 +3715,8 @@ import {
|
|
|
3601
3715
|
fetchConversationTimelineStrict,
|
|
3602
3716
|
fetchRecentConversations,
|
|
3603
3717
|
findLastAssistantSeq,
|
|
3604
|
-
CliError as
|
|
3605
|
-
CliErrorCode as
|
|
3718
|
+
CliError as CliError15,
|
|
3719
|
+
CliErrorCode as CliErrorCode14,
|
|
3606
3720
|
parseInteractionRequest as parseInteractionRequest2,
|
|
3607
3721
|
parseInteractionResolved as parseInteractionResolved2,
|
|
3608
3722
|
buildConfirm as buildConfirm2,
|
|
@@ -3612,51 +3726,51 @@ import {
|
|
|
3612
3726
|
buildSteer
|
|
3613
3727
|
} from "@hcmai/sdk";
|
|
3614
3728
|
import chalk2 from "chalk";
|
|
3615
|
-
import * as
|
|
3729
|
+
import * as fs5 from "fs/promises";
|
|
3616
3730
|
function parseInjectOn(s) {
|
|
3617
|
-
const
|
|
3618
|
-
throw new
|
|
3619
|
-
code:
|
|
3731
|
+
const fail7 = (detail) => {
|
|
3732
|
+
throw new CliError15({
|
|
3733
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3620
3734
|
message: `--inject-on \u683C\u5F0F <eventType>:<action>[:<arg>]\uFF0Caction \u2208 {interrupt, steer}\uFF08steer \u5FC5\u987B\u5E26 content\uFF09\uFF1B${detail}\uFF0C\u6536\u5230 "${s}"`
|
|
3621
3735
|
});
|
|
3622
3736
|
};
|
|
3623
3737
|
const firstColon = s.indexOf(":");
|
|
3624
|
-
if (firstColon < 0) return
|
|
3738
|
+
if (firstColon < 0) return fail7("\u7F3A\u5C11 action \u6BB5");
|
|
3625
3739
|
const eventType = s.slice(0, firstColon);
|
|
3626
3740
|
const rest = s.slice(firstColon + 1);
|
|
3627
3741
|
const secondColon = rest.indexOf(":");
|
|
3628
3742
|
const action = secondColon < 0 ? rest : rest.slice(0, secondColon);
|
|
3629
3743
|
const arg = secondColon < 0 ? void 0 : rest.slice(secondColon + 1);
|
|
3630
|
-
if (!eventType) return
|
|
3744
|
+
if (!eventType) return fail7("eventType \u6BB5\u4E3A\u7A7A");
|
|
3631
3745
|
if (action === "interrupt") {
|
|
3632
|
-
if (arg !== void 0) return
|
|
3746
|
+
if (arg !== void 0) return fail7("interrupt \u4E0D\u63A5\u53D7 arg");
|
|
3633
3747
|
return { eventType, action: "interrupt" };
|
|
3634
3748
|
}
|
|
3635
3749
|
if (action === "steer") {
|
|
3636
|
-
if (arg === void 0 || arg === "") return
|
|
3750
|
+
if (arg === void 0 || arg === "") return fail7("steer \u5FC5\u987B\u5E26 content\uFF08arg\uFF09");
|
|
3637
3751
|
return { eventType, action: "steer", arg };
|
|
3638
3752
|
}
|
|
3639
|
-
return
|
|
3753
|
+
return fail7(`\u672A\u77E5 action "${action}"`);
|
|
3640
3754
|
}
|
|
3641
3755
|
function parseOnConfirm(s) {
|
|
3642
3756
|
if (s === "approve") return { decision: "approve" };
|
|
3643
3757
|
if (s === "reject") return { decision: "reject" };
|
|
3644
3758
|
if (s.startsWith("reject:")) return { decision: "reject", reason: s.slice("reject:".length) };
|
|
3645
|
-
throw new
|
|
3646
|
-
code:
|
|
3759
|
+
throw new CliError15({
|
|
3760
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3647
3761
|
message: `--on-confirm \u53D6\u503C approve | reject | reject:<reason>\uFF0C\u6536\u5230 "${s}"`
|
|
3648
3762
|
});
|
|
3649
3763
|
}
|
|
3650
3764
|
function resolveResumeConversation(args) {
|
|
3651
3765
|
if (args.resume && args.conversation) {
|
|
3652
|
-
throw new
|
|
3653
|
-
code:
|
|
3766
|
+
throw new CliError15({
|
|
3767
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3654
3768
|
message: "--resume \u548C --conversation \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\uFF1B\u65B0\u547D\u4EE4\u8BF7\u7528 --resume <conversationId>"
|
|
3655
3769
|
});
|
|
3656
3770
|
}
|
|
3657
3771
|
if (args.resume === "NEW") {
|
|
3658
|
-
throw new
|
|
3659
|
-
code:
|
|
3772
|
+
throw new CliError15({
|
|
3773
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3660
3774
|
message: "--resume \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u8BF7\u76F4\u63A5\u7701\u7565 --resume"
|
|
3661
3775
|
});
|
|
3662
3776
|
}
|
|
@@ -3667,8 +3781,8 @@ function resolveResumeConversation(args) {
|
|
|
3667
3781
|
function parsePositiveInt(value, fallback, flag) {
|
|
3668
3782
|
const n = Number(value ?? fallback);
|
|
3669
3783
|
if (!Number.isInteger(n) || n <= 0) {
|
|
3670
|
-
throw new
|
|
3671
|
-
code:
|
|
3784
|
+
throw new CliError15({
|
|
3785
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3672
3786
|
message: `${flag} \u9700\u8981\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${value}"`
|
|
3673
3787
|
});
|
|
3674
3788
|
}
|
|
@@ -3691,21 +3805,21 @@ function resolveEventsConversation(args) {
|
|
|
3691
3805
|
const resumeConversationId = resolveResumeConversation(args);
|
|
3692
3806
|
const eventConversationId = typeof args.events === "string" ? args.events.trim() : void 0;
|
|
3693
3807
|
if (eventConversationId === "NEW") {
|
|
3694
|
-
throw new
|
|
3695
|
-
code:
|
|
3808
|
+
throw new CliError15({
|
|
3809
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3696
3810
|
message: "--events \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u6CA1\u6709\u53EF\u67E5\u8BE2\u7684\u4E8B\u4EF6\u6D41"
|
|
3697
3811
|
});
|
|
3698
3812
|
}
|
|
3699
3813
|
if (eventConversationId && resumeConversationId && eventConversationId !== resumeConversationId) {
|
|
3700
|
-
throw new
|
|
3701
|
-
code:
|
|
3814
|
+
throw new CliError15({
|
|
3815
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3702
3816
|
message: "--events <conversationId> \u4E0E --resume/--conversation \u6307\u5411\u4E0D\u540C\u4F1A\u8BDD\uFF1B\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A id"
|
|
3703
3817
|
});
|
|
3704
3818
|
}
|
|
3705
3819
|
const id = eventConversationId || resumeConversationId;
|
|
3706
3820
|
if (!id) {
|
|
3707
|
-
throw new
|
|
3708
|
-
code:
|
|
3821
|
+
throw new CliError15({
|
|
3822
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3709
3823
|
message: "\u67E5\u8BE2\u4E8B\u4EF6\u6D41\u8BF7\u4F20 `hcm chat --events <conversationId>`\uFF0C\u6216 `hcm chat --resume <conversationId> --events`"
|
|
3710
3824
|
});
|
|
3711
3825
|
}
|
|
@@ -3809,8 +3923,8 @@ async function printConversationEvents(conversationId, args) {
|
|
|
3809
3923
|
}
|
|
3810
3924
|
async function printConversationList(args) {
|
|
3811
3925
|
if (args.events || args.resume || args.conversation || args.regenerateFrom || args.promptFile) {
|
|
3812
|
-
throw new
|
|
3813
|
-
code:
|
|
3926
|
+
throw new CliError15({
|
|
3927
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3814
3928
|
message: "--list \u53EA\u7528\u4E8E\u5217\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 --events/--resume/--conversation/--regenerate-from/--prompt-file"
|
|
3815
3929
|
});
|
|
3816
3930
|
}
|
|
@@ -3840,8 +3954,8 @@ async function chatCommand(prompt, args) {
|
|
|
3840
3954
|
try {
|
|
3841
3955
|
if (args.list) {
|
|
3842
3956
|
if (prompt) {
|
|
3843
|
-
throw new
|
|
3844
|
-
code:
|
|
3957
|
+
throw new CliError15({
|
|
3958
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3845
3959
|
message: "--list \u4E0D\u63A5\u53D7 prompt\uFF1B\u7528 `hcm chat --list` \u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD"
|
|
3846
3960
|
});
|
|
3847
3961
|
}
|
|
@@ -3852,8 +3966,8 @@ async function chatCommand(prompt, args) {
|
|
|
3852
3966
|
const eventsConversationId = resolveEventsConversation(args);
|
|
3853
3967
|
if (eventsConversationId) {
|
|
3854
3968
|
if (prompt || args.promptFile || args.regenerateFrom || args.attach?.length) {
|
|
3855
|
-
throw new
|
|
3856
|
-
code:
|
|
3969
|
+
throw new CliError15({
|
|
3970
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3857
3971
|
message: "--events \u662F\u53EA\u8BFB\u67E5\u8BE2\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 prompt/--prompt-file/--regenerate-from/--attach"
|
|
3858
3972
|
});
|
|
3859
3973
|
}
|
|
@@ -3871,15 +3985,15 @@ async function chatCommand(prompt, args) {
|
|
|
3871
3985
|
} else {
|
|
3872
3986
|
regenerateFromSeq = Number(args.regenerateFrom);
|
|
3873
3987
|
if (!Number.isInteger(regenerateFromSeq) || regenerateFromSeq <= 0) {
|
|
3874
|
-
throw new
|
|
3875
|
-
code:
|
|
3988
|
+
throw new CliError15({
|
|
3989
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3876
3990
|
message: `--regenerate-from \u9700\u8981\u6B63\u6574\u6570 journal seq \u6216 last-assistant\uFF0C\u6536\u5230 "${args.regenerateFrom}"`
|
|
3877
3991
|
});
|
|
3878
3992
|
}
|
|
3879
3993
|
}
|
|
3880
3994
|
if (!requestedConversationId) {
|
|
3881
|
-
throw new
|
|
3882
|
-
code:
|
|
3995
|
+
throw new CliError15({
|
|
3996
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3883
3997
|
message: "--regenerate-from \u5FC5\u987B\u914D\u5408 --resume <\u65E2\u5B58\u4F1A\u8BDD id>\uFF08\u91CD\u8DD1\u65E2\u5B58\u6BB5\uFF0C\u65E0\u65B0 prompt\uFF09"
|
|
3884
3998
|
});
|
|
3885
3999
|
}
|
|
@@ -3890,11 +4004,11 @@ async function chatCommand(prompt, args) {
|
|
|
3890
4004
|
return runInkRepl2(args);
|
|
3891
4005
|
}
|
|
3892
4006
|
if (args.promptFile) {
|
|
3893
|
-
prompt = await
|
|
4007
|
+
prompt = await fs5.readFile(args.promptFile, "utf-8");
|
|
3894
4008
|
}
|
|
3895
4009
|
if (prompt === void 0 || !prompt && !regenerateMode) {
|
|
3896
|
-
throw new
|
|
3897
|
-
code:
|
|
4010
|
+
throw new CliError15({
|
|
4011
|
+
code: CliErrorCode14.INVALID_ARGUMENT,
|
|
3898
4012
|
message: "prompt is required (positional or --prompt-file)"
|
|
3899
4013
|
});
|
|
3900
4014
|
}
|
|
@@ -3915,8 +4029,8 @@ async function chatCommand(prompt, args) {
|
|
|
3915
4029
|
const items = await fetchConversationTimeline2(client3.raw(), resumeConversationId);
|
|
3916
4030
|
const lastSeq = findLastAssistantSeq(items);
|
|
3917
4031
|
if (lastSeq == null) {
|
|
3918
|
-
throw new
|
|
3919
|
-
code:
|
|
4032
|
+
throw new CliError15({
|
|
4033
|
+
code: CliErrorCode14.BUSINESS_RULE_VIOLATION,
|
|
3920
4034
|
message: `--regenerate-from last-assistant \u627E\u4E0D\u5230\u53EF\u91CD\u8DD1\u7684 chat-text seq: conversation=${resumeConversationId}`
|
|
3921
4035
|
});
|
|
3922
4036
|
}
|
|
@@ -4136,8 +4250,8 @@ async function chatCommand(prompt, args) {
|
|
|
4136
4250
|
} catch (e) {
|
|
4137
4251
|
process.removeListener("SIGINT", sigintHandler);
|
|
4138
4252
|
await ws.close();
|
|
4139
|
-
throw new
|
|
4140
|
-
code: e.code ??
|
|
4253
|
+
throw new CliError15({
|
|
4254
|
+
code: e.code ?? CliErrorCode14.BUSINESS_RULE_VIOLATION,
|
|
4141
4255
|
message: e.message,
|
|
4142
4256
|
traceId: e.traceId ?? void 0
|
|
4143
4257
|
});
|
|
@@ -4640,7 +4754,7 @@ function emit(result, args, human) {
|
|
|
4640
4754
|
process.exitCode = 0;
|
|
4641
4755
|
return;
|
|
4642
4756
|
}
|
|
4643
|
-
function
|
|
4757
|
+
function fail3(e, args) {
|
|
4644
4758
|
const err = e;
|
|
4645
4759
|
if (err?.isAxiosError) exitWithError(fromAxiosError12(err, args.env));
|
|
4646
4760
|
exitWithError(e);
|
|
@@ -4651,7 +4765,7 @@ async function cacheStatsCommand(model, args) {
|
|
|
4651
4765
|
const stats = await withClient(args, (c) => getCacheStats(c.raw(), model));
|
|
4652
4766
|
emit(stats, args, `\u{1F4CA} ${model} \u7F13\u5B58\u7EDF\u8BA1`);
|
|
4653
4767
|
} catch (e) {
|
|
4654
|
-
|
|
4768
|
+
fail3(e, args);
|
|
4655
4769
|
}
|
|
4656
4770
|
}
|
|
4657
4771
|
async function cacheClearCommand(model, args) {
|
|
@@ -4659,7 +4773,7 @@ async function cacheClearCommand(model, args) {
|
|
|
4659
4773
|
const result = await withClient(args, (c) => clearModelCache(c.raw(), model, args.id));
|
|
4660
4774
|
emit(result, args, args.id ? `\u{1F9F9} \u5DF2\u6E05 ${model}#${args.id} \u7F13\u5B58` : `\u{1F9F9} \u5DF2\u6E05 ${model} \u5168\u90E8\u5B9E\u4F53\u7F13\u5B58`);
|
|
4661
4775
|
} catch (e) {
|
|
4662
|
-
|
|
4776
|
+
fail3(e, args);
|
|
4663
4777
|
}
|
|
4664
4778
|
}
|
|
4665
4779
|
async function cacheClearMetaCommand(model, args) {
|
|
@@ -4671,7 +4785,7 @@ async function cacheClearMetaCommand(model, args) {
|
|
|
4671
4785
|
const scope = args.type ? `${args.type}${args.state ? `.${args.state}` : ""}` : "\u5168\u90E8";
|
|
4672
4786
|
emit(result, args, `\u{1F9F9} \u5DF2\u6E05 ${model} \u5143\u6570\u636E\u7F13\u5B58\uFF08${scope}\uFF09`);
|
|
4673
4787
|
} catch (e) {
|
|
4674
|
-
|
|
4788
|
+
fail3(e, args);
|
|
4675
4789
|
}
|
|
4676
4790
|
}
|
|
4677
4791
|
|
|
@@ -4699,7 +4813,7 @@ function emit2(result, args, human) {
|
|
|
4699
4813
|
process.exitCode = 0;
|
|
4700
4814
|
return;
|
|
4701
4815
|
}
|
|
4702
|
-
function
|
|
4816
|
+
function fail4(e, args) {
|
|
4703
4817
|
const err = e;
|
|
4704
4818
|
if (err?.isAxiosError) exitWithError(fromAxiosError13(err, args.env));
|
|
4705
4819
|
exitWithError(e);
|
|
@@ -4743,7 +4857,7 @@ async function scriptDryRunCommand(args) {
|
|
|
4743
4857
|
const intents = Array.isArray(result?.writeIntents) ? result.writeIntents.length : 0;
|
|
4744
4858
|
emit2(result, args, `\u{1F9EA} dry-run \u5B8C\u6210\uFF1A${args.scriptKey}\uFF08\u62E6\u4E0B ${intents} \u4E2A\u5199\u610F\u56FE\uFF09`);
|
|
4745
4859
|
} catch (e) {
|
|
4746
|
-
|
|
4860
|
+
fail4(e, args);
|
|
4747
4861
|
}
|
|
4748
4862
|
}
|
|
4749
4863
|
async function scriptManifestValidateCommand(args) {
|
|
@@ -4755,7 +4869,7 @@ async function scriptManifestValidateCommand(args) {
|
|
|
4755
4869
|
const result = await withClient2(args, (c) => validateScriptManifest(c.raw(), yaml3));
|
|
4756
4870
|
emit2(result, args, `\u{1F4CB} manifest \u6821\u9A8C\u5B8C\u6210\uFF1A${args.file}`);
|
|
4757
4871
|
} catch (e) {
|
|
4758
|
-
|
|
4872
|
+
fail4(e, args);
|
|
4759
4873
|
}
|
|
4760
4874
|
}
|
|
4761
4875
|
async function scriptLogsCommand(args) {
|
|
@@ -4775,7 +4889,7 @@ async function scriptLogsCommand(args) {
|
|
|
4775
4889
|
);
|
|
4776
4890
|
emit2(page, args, "\u{1F4DC} \u811A\u672C\u6267\u884C\u65E5\u5FD7");
|
|
4777
4891
|
} catch (e) {
|
|
4778
|
-
|
|
4892
|
+
fail4(e, args);
|
|
4779
4893
|
}
|
|
4780
4894
|
}
|
|
4781
4895
|
async function scriptTaskCommand(taskId, args) {
|
|
@@ -4783,7 +4897,7 @@ async function scriptTaskCommand(taskId, args) {
|
|
|
4783
4897
|
const task = await withClient2(args, (c) => getScriptTask(c.raw(), taskId));
|
|
4784
4898
|
emit2(task, args, `\u2699\uFE0F \u4EFB\u52A1 ${taskId}\uFF1A${task?.status ?? "\u672A\u77E5"}\uFF08\u7B2C ${task?.attempts ?? "?"}/${task?.maxAttempts ?? "?"} \u6B21\uFF09`);
|
|
4785
4899
|
} catch (e) {
|
|
4786
|
-
|
|
4900
|
+
fail4(e, args);
|
|
4787
4901
|
}
|
|
4788
4902
|
}
|
|
4789
4903
|
|
|
@@ -4996,8 +5110,8 @@ function emit3(payload, fmt) {
|
|
|
4996
5110
|
init_exit();
|
|
4997
5111
|
import { promises as fsp2 } from "fs";
|
|
4998
5112
|
import os2 from "os";
|
|
4999
|
-
import
|
|
5000
|
-
import { createHash as
|
|
5113
|
+
import path5 from "path";
|
|
5114
|
+
import { createHash as createHash3 } from "crypto";
|
|
5001
5115
|
import {
|
|
5002
5116
|
createHttpClient as createHttpClient2,
|
|
5003
5117
|
fetchSkillCatalog,
|
|
@@ -5018,12 +5132,12 @@ import {
|
|
|
5018
5132
|
loadEnv as loadEnv6,
|
|
5019
5133
|
loadGlobalConfig as loadGlobalConfig6,
|
|
5020
5134
|
resolveActiveEnv as resolveActiveEnv3,
|
|
5021
|
-
CliError as
|
|
5022
|
-
CliErrorCode as
|
|
5135
|
+
CliError as CliError18,
|
|
5136
|
+
CliErrorCode as CliErrorCode17
|
|
5023
5137
|
} from "@hcmai/sdk";
|
|
5024
5138
|
|
|
5025
5139
|
// src/commands/skills-catalog.ts
|
|
5026
|
-
import { flattenSkills, CliError as
|
|
5140
|
+
import { flattenSkills, CliError as CliError16, CliErrorCode as CliErrorCode15 } from "@hcmai/sdk";
|
|
5027
5141
|
var CLI_CATEGORY_KEY = "cli-operations";
|
|
5028
5142
|
var CLI_CATEGORY_NAME = "CLI \u64CD\u4F5C";
|
|
5029
5143
|
function chironEntry(skill) {
|
|
@@ -5066,8 +5180,8 @@ var SOURCE_FILTERS = ["cli", "chiron", "all"];
|
|
|
5066
5180
|
function parseSourceFilter(raw) {
|
|
5067
5181
|
if (raw === void 0) return "all";
|
|
5068
5182
|
if (SOURCE_FILTERS.includes(raw)) return raw;
|
|
5069
|
-
throw new
|
|
5070
|
-
code:
|
|
5183
|
+
throw new CliError16({
|
|
5184
|
+
code: CliErrorCode15.INVALID_ARGUMENT,
|
|
5071
5185
|
message: `--source \u53EA\u8BA4 ${SOURCE_FILTERS.join(" / ")}\uFF0C\u6536\u5230 "${raw}"\u3002\uFF08\`local\` \u4E0D\u662F\u53D6\u503C\uFF1A\u6CA1\u6709\u54EA\u4E00\u8D9F\u4F1A\u53BB\u300C\u626B local \u6765\u6E90\u300D\uFF0Cinstall --from \u88C5\u7684\u90A3\u4E9B\u5728\u4EFB\u4F55 --source \u4E0B\u90FD\u5355\u5217\u3001\u90FD\u4E0D\u53C2\u4E0E\u5347\u7EA7\u3002\uFF09`
|
|
5072
5186
|
});
|
|
5073
5187
|
}
|
|
@@ -5137,13 +5251,13 @@ function checkCrossSourceRequires(catalog) {
|
|
|
5137
5251
|
|
|
5138
5252
|
// src/commands/skills-bundled.ts
|
|
5139
5253
|
import { promises as fsp } from "fs";
|
|
5140
|
-
import * as
|
|
5141
|
-
import { CliError as
|
|
5254
|
+
import * as path4 from "path";
|
|
5255
|
+
import { CliError as CliError17, CliErrorCode as CliErrorCode16, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
|
|
5142
5256
|
|
|
5143
5257
|
// src/commands/skills-manifest.ts
|
|
5144
5258
|
import { readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync3, existsSync } from "fs";
|
|
5145
|
-
import { createHash } from "crypto";
|
|
5146
|
-
import * as
|
|
5259
|
+
import { createHash as createHash2 } from "crypto";
|
|
5260
|
+
import * as path3 from "path";
|
|
5147
5261
|
import { fileURLToPath } from "url";
|
|
5148
5262
|
import { formatObject as formatObject15, parseSkillFrontmatter } from "@hcmai/sdk";
|
|
5149
5263
|
function collectCommandSurface(root) {
|
|
@@ -5160,16 +5274,16 @@ function collectCommandSurface(root) {
|
|
|
5160
5274
|
return out.sort((a, b) => a.path.localeCompare(b.path));
|
|
5161
5275
|
}
|
|
5162
5276
|
function bundledSkillsDir() {
|
|
5163
|
-
const here =
|
|
5164
|
-
return
|
|
5277
|
+
const here = path3.dirname(fileURLToPath(import.meta.url));
|
|
5278
|
+
return path3.join(here, "skills");
|
|
5165
5279
|
}
|
|
5166
5280
|
function sha256(buf) {
|
|
5167
|
-
return
|
|
5281
|
+
return createHash2("sha256").update(buf).digest("hex");
|
|
5168
5282
|
}
|
|
5169
5283
|
function listFiles(dir, rel = "") {
|
|
5170
5284
|
const out = [];
|
|
5171
5285
|
for (const name of readdirSync2(dir)) {
|
|
5172
|
-
const p =
|
|
5286
|
+
const p = path3.join(dir, name);
|
|
5173
5287
|
const r = rel ? `${rel}/${name}` : name;
|
|
5174
5288
|
if (statSync3(p).isDirectory()) out.push(...listFiles(p, r));
|
|
5175
5289
|
else out.push(r);
|
|
@@ -5180,17 +5294,17 @@ function collectBundledSkills(dir = bundledSkillsDir()) {
|
|
|
5180
5294
|
if (!existsSync(dir)) return [];
|
|
5181
5295
|
const out = [];
|
|
5182
5296
|
for (const id of readdirSync2(dir).sort()) {
|
|
5183
|
-
const skillDir =
|
|
5297
|
+
const skillDir = path3.join(dir, id);
|
|
5184
5298
|
if (!statSync3(skillDir).isDirectory()) continue;
|
|
5185
5299
|
const files = listFiles(skillDir).sort();
|
|
5186
5300
|
if (!files.includes("SKILL.md")) continue;
|
|
5187
5301
|
let bytes = 0;
|
|
5188
5302
|
const fileRows = files.map((rel) => {
|
|
5189
|
-
const buf = readFileSync4(
|
|
5303
|
+
const buf = readFileSync4(path3.join(skillDir, rel));
|
|
5190
5304
|
bytes += buf.byteLength;
|
|
5191
5305
|
return { path: rel, bytes: buf.byteLength, sha256: sha256(buf) };
|
|
5192
5306
|
});
|
|
5193
|
-
const body = readFileSync4(
|
|
5307
|
+
const body = readFileSync4(path3.join(skillDir, "SKILL.md"), "utf8");
|
|
5194
5308
|
const fm = parseSkillFrontmatter(body, id);
|
|
5195
5309
|
out.push({
|
|
5196
5310
|
id,
|
|
@@ -5230,14 +5344,14 @@ function listBundledSkills(dir = bundledSkillsDir()) {
|
|
|
5230
5344
|
return collectBundledSkills(dir);
|
|
5231
5345
|
}
|
|
5232
5346
|
function unreachable(id, detail) {
|
|
5233
|
-
return new
|
|
5234
|
-
code:
|
|
5347
|
+
return new CliError17({
|
|
5348
|
+
code: CliErrorCode16.SKILL_SOURCE_UNREACHABLE,
|
|
5235
5349
|
message: `\u88C5\u5728\u8FD9\u4EFD CLI \u91CC\u7684\u6280\u80FD\u8D44\u6E90\u8BFB\u4E0D\u5230\uFF08${detail}\uFF09\uFF0C\u91CD\u88C5 @hcmai/cli\u3002
|
|
5236
5350
|
\u6280\u80FD id\uFF1A${id}\uFF1B\u627E\u7684\u4F4D\u7F6E\uFF1A${bundledSkillsDir()}`
|
|
5237
5351
|
});
|
|
5238
5352
|
}
|
|
5239
5353
|
async function readBundledReferences(skillDir) {
|
|
5240
|
-
const root =
|
|
5354
|
+
const root = path4.join(skillDir, "references");
|
|
5241
5355
|
const out = [];
|
|
5242
5356
|
const walk = async (dir, prefix) => {
|
|
5243
5357
|
let items;
|
|
@@ -5250,22 +5364,22 @@ async function readBundledReferences(skillDir) {
|
|
|
5250
5364
|
for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5251
5365
|
const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
|
|
5252
5366
|
if (item.isDirectory()) {
|
|
5253
|
-
await walk(
|
|
5367
|
+
await walk(path4.join(dir, item.name), relative2);
|
|
5254
5368
|
continue;
|
|
5255
5369
|
}
|
|
5256
5370
|
if (!item.isFile()) continue;
|
|
5257
5371
|
assertSafeReferencePath(relative2);
|
|
5258
|
-
out.push({ path: relative2, content: await fsp.readFile(
|
|
5372
|
+
out.push({ path: relative2, content: await fsp.readFile(path4.join(dir, item.name), "utf8") });
|
|
5259
5373
|
}
|
|
5260
5374
|
};
|
|
5261
5375
|
await walk(root, "");
|
|
5262
5376
|
return out;
|
|
5263
5377
|
}
|
|
5264
5378
|
async function readBundledSkillDocument(id, dir = bundledSkillsDir()) {
|
|
5265
|
-
const skillDir =
|
|
5379
|
+
const skillDir = path4.join(dir, id);
|
|
5266
5380
|
let markdown;
|
|
5267
5381
|
try {
|
|
5268
|
-
markdown = await fsp.readFile(
|
|
5382
|
+
markdown = await fsp.readFile(path4.join(skillDir, "SKILL.md"), "utf8");
|
|
5269
5383
|
} catch (cause) {
|
|
5270
5384
|
if (cause?.code === "ENOENT") throw unreachable(id, "SKILL.md \u4E0D\u5B58\u5728");
|
|
5271
5385
|
throw cause;
|
|
@@ -5288,8 +5402,8 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
|
|
|
5288
5402
|
const visit = async (id) => {
|
|
5289
5403
|
if (state.get(id) === "done") return;
|
|
5290
5404
|
if (state.get(id) === "visiting") {
|
|
5291
|
-
throw new
|
|
5292
|
-
code:
|
|
5405
|
+
throw new CliError17({
|
|
5406
|
+
code: CliErrorCode16.INVALID_ARGUMENT,
|
|
5293
5407
|
message: `\u81EA\u5E26\u6280\u80FD\u4F9D\u8D56\u6210\u73AF\uFF1A${[...stack, id].join(" \u2192 ")}`
|
|
5294
5408
|
});
|
|
5295
5409
|
}
|
|
@@ -5323,7 +5437,7 @@ function migrateSkillsState(state) {
|
|
|
5323
5437
|
return { ...state, skills: skills2 };
|
|
5324
5438
|
}
|
|
5325
5439
|
function sha2562(text) {
|
|
5326
|
-
return
|
|
5440
|
+
return createHash3("sha256").update(text, "utf8").digest("hex");
|
|
5327
5441
|
}
|
|
5328
5442
|
async function resolveEndpoint(args) {
|
|
5329
5443
|
if (args.endpoint) return args.endpoint.replace(/\/+$/, "");
|
|
@@ -5331,8 +5445,8 @@ async function resolveEndpoint(args) {
|
|
|
5331
5445
|
const envName = resolveActiveEnv3({ envFlag: args.env }, process.env, g);
|
|
5332
5446
|
const env3 = await loadEnv6(envName).catch(() => null);
|
|
5333
5447
|
if (!env3?.endpoint) {
|
|
5334
|
-
throw new
|
|
5335
|
-
code:
|
|
5448
|
+
throw new CliError18({
|
|
5449
|
+
code: CliErrorCode17.MISSING_FLAG,
|
|
5336
5450
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
|
|
5337
5451
|
});
|
|
5338
5452
|
}
|
|
@@ -5351,8 +5465,8 @@ function decideTrackedEndpoint(options) {
|
|
|
5351
5465
|
}
|
|
5352
5466
|
if (!recorded) {
|
|
5353
5467
|
if (!current) {
|
|
5354
|
-
throw new
|
|
5355
|
-
code:
|
|
5468
|
+
throw new CliError18({
|
|
5469
|
+
code: CliErrorCode17.MISSING_FLAG,
|
|
5356
5470
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
|
|
5357
5471
|
});
|
|
5358
5472
|
}
|
|
@@ -5376,27 +5490,27 @@ async function exists(target) {
|
|
|
5376
5490
|
}
|
|
5377
5491
|
}
|
|
5378
5492
|
async function detectTarget(cwd) {
|
|
5379
|
-
if (await exists(
|
|
5380
|
-
if (await exists(
|
|
5381
|
-
if (await exists(
|
|
5493
|
+
if (await exists(path5.join(cwd, ".claude"))) return "claude";
|
|
5494
|
+
if (await exists(path5.join(cwd, "AGENTS.md"))) return "codex";
|
|
5495
|
+
if (await exists(path5.join(cwd, ".codex"))) return "codex";
|
|
5382
5496
|
return void 0;
|
|
5383
5497
|
}
|
|
5384
5498
|
async function resolveInstallLayout(args, cwd = process.cwd()) {
|
|
5385
5499
|
const requested = args.target && args.target !== "auto" ? args.target : void 0;
|
|
5386
5500
|
const target = requested ?? await detectTarget(cwd) ?? "claude";
|
|
5387
5501
|
if (target === "codex") {
|
|
5388
|
-
const root = args.global ?
|
|
5389
|
-
const claudeFile =
|
|
5502
|
+
const root = args.global ? path5.join(os2.homedir(), ".codex") : cwd;
|
|
5503
|
+
const claudeFile = path5.join(root, "CLAUDE.md");
|
|
5390
5504
|
return {
|
|
5391
5505
|
target,
|
|
5392
|
-
baseDir: args.dir ?
|
|
5393
|
-
agentsFile:
|
|
5506
|
+
baseDir: args.dir ? path5.resolve(args.dir) : path5.join(root, "hcm-skills"),
|
|
5507
|
+
agentsFile: path5.join(root, "AGENTS.md"),
|
|
5394
5508
|
companionAgentFiles: !args.global && await exists(claudeFile) ? [claudeFile] : []
|
|
5395
5509
|
};
|
|
5396
5510
|
}
|
|
5397
5511
|
return {
|
|
5398
5512
|
target,
|
|
5399
|
-
baseDir: args.dir ?
|
|
5513
|
+
baseDir: args.dir ? path5.resolve(args.dir) : args.global ? path5.join(os2.homedir(), ".claude", "skills") : path5.join(cwd, ".claude", "skills")
|
|
5400
5514
|
};
|
|
5401
5515
|
}
|
|
5402
5516
|
async function chironClient(args) {
|
|
@@ -5409,7 +5523,7 @@ async function chironClient(args) {
|
|
|
5409
5523
|
});
|
|
5410
5524
|
return { http, endpoint, base: await resolveChironBase(http) };
|
|
5411
5525
|
}
|
|
5412
|
-
function
|
|
5526
|
+
function fail5(e, args) {
|
|
5413
5527
|
const err = e;
|
|
5414
5528
|
if (err?.response?.status === 404) {
|
|
5415
5529
|
exitWithError(new Error("\u8BE5\u73AF\u5883\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD \u2014\u2014 \u8DD1 `hcm skills list` \u770B\u76EE\u5F55\uFF08\u6280\u80FD\u968F\u4EA7\u54C1\u7248\u672C\u8D70\uFF09"));
|
|
@@ -5433,8 +5547,8 @@ async function skillsListCommand(keyword, args) {
|
|
|
5433
5547
|
const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
|
|
5434
5548
|
const conflicts = detectIdConflicts(catalog);
|
|
5435
5549
|
if (conflicts.ids.length > 0) {
|
|
5436
|
-
throw new
|
|
5437
|
-
code:
|
|
5550
|
+
throw new CliError18({
|
|
5551
|
+
code: CliErrorCode17.SKILL_ID_CONFLICT,
|
|
5438
5552
|
message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
|
|
5439
5553
|
});
|
|
5440
5554
|
}
|
|
@@ -5542,7 +5656,7 @@ async function skillsListCommand(keyword, args) {
|
|
|
5542
5656
|
process.exitCode = 0;
|
|
5543
5657
|
return;
|
|
5544
5658
|
} catch (e) {
|
|
5545
|
-
|
|
5659
|
+
fail5(e, args);
|
|
5546
5660
|
}
|
|
5547
5661
|
}
|
|
5548
5662
|
async function listInstalledSkills(keyword, args) {
|
|
@@ -5555,7 +5669,7 @@ async function listInstalledSkills(keyword, args) {
|
|
|
5555
5669
|
process.exitCode = 0;
|
|
5556
5670
|
return;
|
|
5557
5671
|
}
|
|
5558
|
-
process.stdout.write(`${
|
|
5672
|
+
process.stdout.write(`${path5.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
|
|
5559
5673
|
`);
|
|
5560
5674
|
process.stdout.write(" \u88C5\u5168\u90E8\uFF1Ahcm skills install --all\n");
|
|
5561
5675
|
process.exitCode = 0;
|
|
@@ -5660,7 +5774,7 @@ async function skillsShowCommand(id, args) {
|
|
|
5660
5774
|
process.exitCode = 0;
|
|
5661
5775
|
return;
|
|
5662
5776
|
} catch (e) {
|
|
5663
|
-
|
|
5777
|
+
fail5(e, args);
|
|
5664
5778
|
}
|
|
5665
5779
|
}
|
|
5666
5780
|
async function skillsInstallCommand(id, args) {
|
|
@@ -5677,7 +5791,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
5677
5791
|
let manifest2;
|
|
5678
5792
|
let conflictNote;
|
|
5679
5793
|
if (args.from) {
|
|
5680
|
-
const root =
|
|
5794
|
+
const root = path5.resolve(args.from);
|
|
5681
5795
|
requestedIds = all ? await listLocalSkillIds(root) : [id];
|
|
5682
5796
|
const seen = /* @__PURE__ */ new Set();
|
|
5683
5797
|
documents = [];
|
|
@@ -5707,8 +5821,8 @@ async function skillsInstallCommand(id, args) {
|
|
|
5707
5821
|
const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
|
|
5708
5822
|
const conflicts = detectIdConflicts(catalog);
|
|
5709
5823
|
if (conflicts.ids.length > 0) {
|
|
5710
|
-
throw new
|
|
5711
|
-
code:
|
|
5824
|
+
throw new CliError18({
|
|
5825
|
+
code: CliErrorCode17.SKILL_ID_CONFLICT,
|
|
5712
5826
|
message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
|
|
5713
5827
|
});
|
|
5714
5828
|
}
|
|
@@ -5793,7 +5907,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
5793
5907
|
if (fmt === "json" || fmt === "yaml") {
|
|
5794
5908
|
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");
|
|
5795
5909
|
} else {
|
|
5796
|
-
const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${
|
|
5910
|
+
const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path5.join(result.baseDir, id, "SKILL.md")}`;
|
|
5797
5911
|
process.stdout.write(`${headline}
|
|
5798
5912
|
`);
|
|
5799
5913
|
if (result.installed.length > 0) {
|
|
@@ -5812,11 +5926,11 @@ async function skillsInstallCommand(id, args) {
|
|
|
5812
5926
|
`);
|
|
5813
5927
|
}
|
|
5814
5928
|
for (const index of agentIndexes) {
|
|
5815
|
-
const reader =
|
|
5929
|
+
const reader = path5.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
|
|
5816
5930
|
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
|
|
5817
5931
|
`);
|
|
5818
5932
|
}
|
|
5819
|
-
process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ?
|
|
5933
|
+
process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path5.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
|
|
5820
5934
|
`);
|
|
5821
5935
|
if (conflictNote) process.stdout.write(` \u26A0\uFE0F ${conflictNote}
|
|
5822
5936
|
`);
|
|
@@ -5825,7 +5939,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
5825
5939
|
process.exitCode = 0;
|
|
5826
5940
|
return;
|
|
5827
5941
|
} catch (e) {
|
|
5828
|
-
|
|
5942
|
+
fail5(e, args);
|
|
5829
5943
|
}
|
|
5830
5944
|
}
|
|
5831
5945
|
var FETCH_CONCURRENCY = 6;
|
|
@@ -5852,7 +5966,7 @@ async function listLocalSkillIds(root) {
|
|
|
5852
5966
|
const ids = [];
|
|
5853
5967
|
for (const entry of entries) {
|
|
5854
5968
|
if (!entry.isDirectory()) continue;
|
|
5855
|
-
if (await exists(
|
|
5969
|
+
if (await exists(path5.join(root, entry.name, "SKILL.md"))) ids.push(entry.name);
|
|
5856
5970
|
}
|
|
5857
5971
|
if (ids.length === 0) throw invalid(`\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709\u4EFB\u4F55 <id>/SKILL.md\uFF1A${root}`);
|
|
5858
5972
|
return ids.sort();
|
|
@@ -5882,17 +5996,17 @@ async function syncAgentIndexes(layout, manifest2) {
|
|
|
5882
5996
|
const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
|
|
5883
5997
|
const results = [];
|
|
5884
5998
|
for (const file of files) {
|
|
5885
|
-
const agentsDir =
|
|
5999
|
+
const agentsDir = path5.dirname(file);
|
|
5886
6000
|
const entries = Object.keys(state.skills).sort().map((id) => {
|
|
5887
6001
|
const known = catalog.get(id);
|
|
5888
|
-
const absolute =
|
|
5889
|
-
let relative2 =
|
|
6002
|
+
const absolute = path5.join(layout.baseDir, id, "SKILL.md");
|
|
6003
|
+
let relative2 = path5.relative(agentsDir, absolute);
|
|
5890
6004
|
if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
|
|
5891
6005
|
return {
|
|
5892
6006
|
id,
|
|
5893
6007
|
title: known?.title ?? id,
|
|
5894
6008
|
description: known?.description ?? "",
|
|
5895
|
-
relativePath: relative2.split(
|
|
6009
|
+
relativePath: relative2.split(path5.sep).join("/")
|
|
5896
6010
|
};
|
|
5897
6011
|
});
|
|
5898
6012
|
results.push({ file, status: await upsertAgentsBlock(file, renderAgentsBlock(entries)) });
|
|
@@ -5912,13 +6026,13 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
|
|
|
5912
6026
|
throw invalid(`\u6280\u80FD\u4F9D\u8D56\u5B58\u5728\u73AF: ${[...pathStack.slice(Math.max(0, start)), id].join(" -> ")}`);
|
|
5913
6027
|
}
|
|
5914
6028
|
assertSafeSkillId(id);
|
|
5915
|
-
const local =
|
|
6029
|
+
const local = path5.join(sourceRoot, id, "SKILL.md");
|
|
5916
6030
|
let markdown;
|
|
5917
6031
|
try {
|
|
5918
6032
|
markdown = await fsp2.readFile(local, "utf8");
|
|
5919
6033
|
} catch (cause) {
|
|
5920
6034
|
if (cause?.code === "ENOENT") {
|
|
5921
|
-
throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${
|
|
6035
|
+
throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${path5.join(sourceRoot, id)}`);
|
|
5922
6036
|
}
|
|
5923
6037
|
throw cause;
|
|
5924
6038
|
}
|
|
@@ -5930,7 +6044,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
|
|
|
5930
6044
|
markdown,
|
|
5931
6045
|
source: local,
|
|
5932
6046
|
sourceKind: "local",
|
|
5933
|
-
references: await readLocalReferences(
|
|
6047
|
+
references: await readLocalReferences(path5.join(sourceRoot, id))
|
|
5934
6048
|
};
|
|
5935
6049
|
for (const required of parseSkillRequirements2(markdown, id)) {
|
|
5936
6050
|
await visit(required, id);
|
|
@@ -5944,7 +6058,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
|
|
|
5944
6058
|
}
|
|
5945
6059
|
async function readSkillsState(baseDir) {
|
|
5946
6060
|
try {
|
|
5947
|
-
const raw = await fsp2.readFile(
|
|
6061
|
+
const raw = await fsp2.readFile(path5.join(baseDir, SKILLS_STATE_FILE), "utf8");
|
|
5948
6062
|
const parsed = JSON.parse(raw);
|
|
5949
6063
|
if (!parsed || typeof parsed !== "object" || !parsed.skills) return void 0;
|
|
5950
6064
|
return migrateSkillsState(parsed);
|
|
@@ -5954,7 +6068,7 @@ async function readSkillsState(baseDir) {
|
|
|
5954
6068
|
}
|
|
5955
6069
|
async function writeSkillsState(baseDir, state) {
|
|
5956
6070
|
await fsp2.mkdir(baseDir, { recursive: true });
|
|
5957
|
-
const file =
|
|
6071
|
+
const file = path5.join(baseDir, SKILLS_STATE_FILE);
|
|
5958
6072
|
const temp = `${file}.${process.pid}.tmp`;
|
|
5959
6073
|
await fsp2.writeFile(temp, JSON.stringify(state, null, 2) + "\n", "utf8");
|
|
5960
6074
|
await fsp2.rename(temp, file);
|
|
@@ -5983,7 +6097,7 @@ async function upsertAgentsBlock(agentsFile, block) {
|
|
|
5983
6097
|
existing = await fsp2.readFile(agentsFile, "utf8");
|
|
5984
6098
|
} catch (cause) {
|
|
5985
6099
|
if (cause?.code !== "ENOENT") throw cause;
|
|
5986
|
-
await fsp2.mkdir(
|
|
6100
|
+
await fsp2.mkdir(path5.dirname(agentsFile), { recursive: true });
|
|
5987
6101
|
await fsp2.writeFile(agentsFile, block + "\n", "utf8");
|
|
5988
6102
|
return "created";
|
|
5989
6103
|
}
|
|
@@ -6009,7 +6123,7 @@ async function installSkillDocuments(documents, requestedIds, baseDir, force, me
|
|
|
6009
6123
|
if (!document.markdown.trim()) throw invalid(`\u6280\u80FD ${document.id} \u5185\u5BB9\u4E3A\u7A7A`);
|
|
6010
6124
|
return {
|
|
6011
6125
|
...document,
|
|
6012
|
-
target:
|
|
6126
|
+
target: path5.join(baseDir, document.id, "SKILL.md"),
|
|
6013
6127
|
bytes: Buffer.byteLength(document.markdown)
|
|
6014
6128
|
};
|
|
6015
6129
|
});
|
|
@@ -6060,7 +6174,7 @@ async function sameOnDisk(baseDir, candidate) {
|
|
|
6060
6174
|
return true;
|
|
6061
6175
|
}
|
|
6062
6176
|
async function readLocalReferences(skillDir) {
|
|
6063
|
-
const root =
|
|
6177
|
+
const root = path5.join(skillDir, "references");
|
|
6064
6178
|
const out = [];
|
|
6065
6179
|
const walk = async (dir, prefix) => {
|
|
6066
6180
|
let items;
|
|
@@ -6073,12 +6187,12 @@ async function readLocalReferences(skillDir) {
|
|
|
6073
6187
|
for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6074
6188
|
const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
|
|
6075
6189
|
if (item.isDirectory()) {
|
|
6076
|
-
await walk(
|
|
6190
|
+
await walk(path5.join(dir, item.name), relative2);
|
|
6077
6191
|
continue;
|
|
6078
6192
|
}
|
|
6079
6193
|
if (!item.isFile()) continue;
|
|
6080
6194
|
assertSafeReferencePath2(relative2);
|
|
6081
|
-
out.push({ path: relative2, content: await fsp2.readFile(
|
|
6195
|
+
out.push({ path: relative2, content: await fsp2.readFile(path5.join(dir, item.name), "utf8") });
|
|
6082
6196
|
}
|
|
6083
6197
|
};
|
|
6084
6198
|
await walk(root, "");
|
|
@@ -6109,15 +6223,15 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
|
|
|
6109
6223
|
const removed = [];
|
|
6110
6224
|
try {
|
|
6111
6225
|
for (const document of documents) {
|
|
6112
|
-
const target =
|
|
6113
|
-
await fsp2.mkdir(
|
|
6114
|
-
const temp =
|
|
6226
|
+
const target = path5.join(baseDir, document.id, "SKILL.md");
|
|
6227
|
+
await fsp2.mkdir(path5.dirname(target), { recursive: true });
|
|
6228
|
+
const temp = path5.join(path5.dirname(target), `.SKILL.md.${process.pid}.${Date.now()}.tmp`);
|
|
6115
6229
|
await fsp2.writeFile(temp, document.markdown, "utf8");
|
|
6116
6230
|
staged.push({ temp, target });
|
|
6117
6231
|
for (const reference of document.references ?? []) {
|
|
6118
6232
|
assertSafeReferencePath2(reference.path);
|
|
6119
|
-
const referenceTarget =
|
|
6120
|
-
await fsp2.mkdir(
|
|
6233
|
+
const referenceTarget = path5.join(baseDir, document.id, "references", reference.path);
|
|
6234
|
+
await fsp2.mkdir(path5.dirname(referenceTarget), { recursive: true });
|
|
6121
6235
|
const referenceTemp = `${referenceTarget}.${process.pid}.${Date.now()}.tmp`;
|
|
6122
6236
|
await fsp2.writeFile(referenceTemp, reference.content, "utf8");
|
|
6123
6237
|
staged.push({ temp: referenceTemp, target: referenceTarget });
|
|
@@ -6125,7 +6239,7 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
|
|
|
6125
6239
|
}
|
|
6126
6240
|
for (const stale of removals) {
|
|
6127
6241
|
assertSafeReferencePath2(stale.path);
|
|
6128
|
-
const original =
|
|
6242
|
+
const original = path5.join(baseDir, stale.id, "references", stale.path);
|
|
6129
6243
|
const parked = `${original}.${process.pid}.${Date.now()}.removed`;
|
|
6130
6244
|
await fsp2.rename(original, parked);
|
|
6131
6245
|
removed.push({ parked, original });
|
|
@@ -6171,11 +6285,11 @@ async function recordInstalled(baseDir, documents, meta2) {
|
|
|
6171
6285
|
return state;
|
|
6172
6286
|
}
|
|
6173
6287
|
function invalid(message) {
|
|
6174
|
-
return new
|
|
6288
|
+
return new CliError18({ code: CliErrorCode17.INVALID_ARGUMENT, message });
|
|
6175
6289
|
}
|
|
6176
6290
|
async function readInstalled(baseDir, id) {
|
|
6177
6291
|
try {
|
|
6178
|
-
return await fsp2.readFile(
|
|
6292
|
+
return await fsp2.readFile(path5.join(baseDir, id, "SKILL.md"), "utf8");
|
|
6179
6293
|
} catch (cause) {
|
|
6180
6294
|
if (cause?.code === "ENOENT") return void 0;
|
|
6181
6295
|
throw cause;
|
|
@@ -6183,7 +6297,7 @@ async function readInstalled(baseDir, id) {
|
|
|
6183
6297
|
}
|
|
6184
6298
|
async function readInstalledReference(baseDir, id, relative2) {
|
|
6185
6299
|
try {
|
|
6186
|
-
return await fsp2.readFile(
|
|
6300
|
+
return await fsp2.readFile(path5.join(baseDir, id, "references", relative2), "utf8");
|
|
6187
6301
|
} catch (cause) {
|
|
6188
6302
|
if (cause?.code === "ENOENT") return void 0;
|
|
6189
6303
|
throw cause;
|
|
@@ -6315,9 +6429,9 @@ async function skillsUpdateCommand(args) {
|
|
|
6315
6429
|
const layout = await resolveInstallLayout(args);
|
|
6316
6430
|
const state = await readSkillsState(layout.baseDir);
|
|
6317
6431
|
if (!state || Object.keys(state.skills).length === 0) {
|
|
6318
|
-
throw new
|
|
6319
|
-
code:
|
|
6320
|
-
message: `${
|
|
6432
|
+
throw new CliError18({
|
|
6433
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
6434
|
+
message: `${path5.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u6709\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002\u5148 \`hcm skills install <id>\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u91CD\u88C5\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
|
|
6321
6435
|
});
|
|
6322
6436
|
}
|
|
6323
6437
|
const source = parseSourceFilter(args.source);
|
|
@@ -6436,7 +6550,7 @@ async function skillsUpdateCommand(args) {
|
|
|
6436
6550
|
process.exitCode = 0;
|
|
6437
6551
|
return;
|
|
6438
6552
|
} catch (e) {
|
|
6439
|
-
|
|
6553
|
+
fail5(e, args);
|
|
6440
6554
|
}
|
|
6441
6555
|
}
|
|
6442
6556
|
|
|
@@ -6449,8 +6563,8 @@ import {
|
|
|
6449
6563
|
loadEnv as loadEnv7,
|
|
6450
6564
|
loadGlobalConfig as loadGlobalConfig7,
|
|
6451
6565
|
resolveActiveEnv as resolveActiveEnv4,
|
|
6452
|
-
CliError as
|
|
6453
|
-
CliErrorCode as
|
|
6566
|
+
CliError as CliError19,
|
|
6567
|
+
CliErrorCode as CliErrorCode18
|
|
6454
6568
|
} from "@hcmai/sdk";
|
|
6455
6569
|
init_exit();
|
|
6456
6570
|
async function resolveBootstrapKey(args, stdinTaken) {
|
|
@@ -6458,8 +6572,8 @@ async function resolveBootstrapKey(args, stdinTaken) {
|
|
|
6458
6572
|
if (fromEnv) return fromEnv;
|
|
6459
6573
|
if (args.bootstrapKeyStdin) {
|
|
6460
6574
|
if (stdinTaken) {
|
|
6461
|
-
throw new
|
|
6462
|
-
code:
|
|
6575
|
+
throw new CliError19({
|
|
6576
|
+
code: CliErrorCode18.INVALID_ARGUMENT,
|
|
6463
6577
|
message: "--bootstrap-key-stdin \u4E0E --admin-password-stdin \u4E0D\u80FD\u540C\u65F6\u7528\uFF08stdin \u53EA\u6709\u4E00\u8DEF\uFF09\uFF1B\u628A\u5176\u4E2D\u4E00\u4E2A\u6539\u8D70 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\u6216\u4EA4\u4E92\u8F93\u5165"
|
|
6464
6578
|
});
|
|
6465
6579
|
}
|
|
@@ -6489,8 +6603,8 @@ async function resolveEndpoint2(args) {
|
|
|
6489
6603
|
const envName = resolveActiveEnv4({ envFlag: args.env }, process.env, g);
|
|
6490
6604
|
const env3 = await loadEnv7(envName).catch(() => null);
|
|
6491
6605
|
if (!env3?.endpoint) {
|
|
6492
|
-
throw new
|
|
6493
|
-
code:
|
|
6606
|
+
throw new CliError19({
|
|
6607
|
+
code: CliErrorCode18.MISSING_FLAG,
|
|
6494
6608
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
|
|
6495
6609
|
});
|
|
6496
6610
|
}
|
|
@@ -6499,8 +6613,8 @@ async function resolveEndpoint2(args) {
|
|
|
6499
6613
|
async function tenantBootstrapCommand(args) {
|
|
6500
6614
|
try {
|
|
6501
6615
|
if (!args.tenantId || !args.adminUsername) {
|
|
6502
|
-
throw new
|
|
6503
|
-
code:
|
|
6616
|
+
throw new CliError19({
|
|
6617
|
+
code: CliErrorCode18.MISSING_FLAG,
|
|
6504
6618
|
message: "--tenant-id \u4E0E --admin-username \u5FC5\u586B"
|
|
6505
6619
|
});
|
|
6506
6620
|
}
|
|
@@ -6568,15 +6682,15 @@ import {
|
|
|
6568
6682
|
formatMetaIssues,
|
|
6569
6683
|
explainJacksonError,
|
|
6570
6684
|
META_SCHEMA_SOURCE_COMMIT,
|
|
6571
|
-
CliError as
|
|
6572
|
-
CliErrorCode as
|
|
6685
|
+
CliError as CliError20,
|
|
6686
|
+
CliErrorCode as CliErrorCode19
|
|
6573
6687
|
} from "@hcmai/sdk";
|
|
6574
6688
|
init_exit();
|
|
6575
6689
|
init_auth_guard();
|
|
6576
6690
|
async function client2(args) {
|
|
6577
6691
|
return HcmClient18.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
6578
6692
|
}
|
|
6579
|
-
function
|
|
6693
|
+
function fail6(e, args) {
|
|
6580
6694
|
const err = e;
|
|
6581
6695
|
if (err?.response?.status === 403) {
|
|
6582
6696
|
exitWithError(
|
|
@@ -6603,23 +6717,23 @@ async function metaListCommand(args) {
|
|
|
6603
6717
|
process.exitCode = 0;
|
|
6604
6718
|
return;
|
|
6605
6719
|
} catch (e) {
|
|
6606
|
-
|
|
6720
|
+
fail6(e, args);
|
|
6607
6721
|
}
|
|
6608
6722
|
}
|
|
6609
|
-
async function metaGetCommand(
|
|
6723
|
+
async function metaGetCommand(path19, args) {
|
|
6610
6724
|
try {
|
|
6611
6725
|
const c = await client2(args);
|
|
6612
|
-
const content = await getTenantMeta(c.raw(),
|
|
6726
|
+
const content = await getTenantMeta(c.raw(), path19);
|
|
6613
6727
|
process.stdout.write(content.endsWith("\n") ? content : content + "\n");
|
|
6614
6728
|
process.exitCode = 0;
|
|
6615
6729
|
return;
|
|
6616
6730
|
} catch (e) {
|
|
6617
|
-
|
|
6731
|
+
fail6(e, args);
|
|
6618
6732
|
}
|
|
6619
6733
|
}
|
|
6620
6734
|
var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
|
|
6621
|
-
function parseMetaPath(
|
|
6622
|
-
const base =
|
|
6735
|
+
function parseMetaPath(path19) {
|
|
6736
|
+
const base = path19.split(/[\\/]/).pop() ?? path19;
|
|
6623
6737
|
if (!/\.(yml|yaml)$/i.test(base)) return {};
|
|
6624
6738
|
const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
|
|
6625
6739
|
return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
|
|
@@ -6636,10 +6750,10 @@ function unverifiableReason(e) {
|
|
|
6636
6750
|
if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
|
|
6637
6751
|
return void 0;
|
|
6638
6752
|
}
|
|
6639
|
-
async function verifyAfterWrite(c,
|
|
6640
|
-
const { model, kind, state } = parseMetaPath(
|
|
6753
|
+
async function verifyAfterWrite(c, path19) {
|
|
6754
|
+
const { model, kind, state } = parseMetaPath(path19);
|
|
6641
6755
|
if (!model || !kind) {
|
|
6642
|
-
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${
|
|
6756
|
+
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path19} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
|
|
6643
6757
|
}
|
|
6644
6758
|
try {
|
|
6645
6759
|
await clearMetaCache2(c.raw(), model, {});
|
|
@@ -6684,11 +6798,11 @@ async function verifyAfterWrite(c, path18) {
|
|
|
6684
6798
|
}
|
|
6685
6799
|
return { status: "ok" };
|
|
6686
6800
|
}
|
|
6687
|
-
async function metaSetCommand(
|
|
6801
|
+
async function metaSetCommand(path19, args) {
|
|
6688
6802
|
try {
|
|
6689
6803
|
if (!args.file) {
|
|
6690
|
-
throw new
|
|
6691
|
-
code:
|
|
6804
|
+
throw new CliError20({
|
|
6805
|
+
code: CliErrorCode19.MISSING_FLAG,
|
|
6692
6806
|
message: "--file <path> \u5FC5\u586B\uFF08\u4ECE\u6587\u4EF6\u8BFB\u53D6 meta \u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
|
|
6693
6807
|
});
|
|
6694
6808
|
}
|
|
@@ -6700,9 +6814,9 @@ async function metaSetCommand(path18, args) {
|
|
|
6700
6814
|
process.stdin.on("error", reject);
|
|
6701
6815
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6702
6816
|
if (!args.skipValidate) {
|
|
6703
|
-
const result2 = validateMetaContent(
|
|
6817
|
+
const result2 = validateMetaContent(path19, content);
|
|
6704
6818
|
if (result2.issues.length > 0) {
|
|
6705
|
-
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${
|
|
6819
|
+
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path19}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
|
|
6706
6820
|
`);
|
|
6707
6821
|
process.stderr.write(formatMetaIssues(result2, " ") + "\n");
|
|
6708
6822
|
}
|
|
@@ -6721,13 +6835,13 @@ async function metaSetCommand(path18, args) {
|
|
|
6721
6835
|
if (dryFmt === "json" || dryFmt === "yaml") {
|
|
6722
6836
|
process.stdout.write(
|
|
6723
6837
|
formatObject18(
|
|
6724
|
-
{ dryRun: true, path:
|
|
6838
|
+
{ dryRun: true, path: path19, bytes: Buffer.byteLength(content), content },
|
|
6725
6839
|
{ format: dryFmt }
|
|
6726
6840
|
) + "\n"
|
|
6727
6841
|
);
|
|
6728
6842
|
} else {
|
|
6729
6843
|
process.stdout.write(
|
|
6730
|
-
`[dry-run] \u5C06\u5199\u5165 ${
|
|
6844
|
+
`[dry-run] \u5C06\u5199\u5165 ${path19}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
|
|
6731
6845
|
---
|
|
6732
6846
|
${content}
|
|
6733
6847
|
`
|
|
@@ -6741,13 +6855,13 @@ ${content}
|
|
|
6741
6855
|
let backupState = "unknown";
|
|
6742
6856
|
let backupWhy;
|
|
6743
6857
|
try {
|
|
6744
|
-
const prev = await getTenantMeta(c.raw(),
|
|
6858
|
+
const prev = await getTenantMeta(c.raw(), path19);
|
|
6745
6859
|
if (!prev || prev.trim() === "") {
|
|
6746
6860
|
backupState = "absent";
|
|
6747
6861
|
} else {
|
|
6748
6862
|
backupFile = nodePath.join(
|
|
6749
6863
|
os3.tmpdir(),
|
|
6750
|
-
`hcm-meta-backup-${Date.now()}-${
|
|
6864
|
+
`hcm-meta-backup-${Date.now()}-${path19.replace(/[\\/]/g, "_")}`
|
|
6751
6865
|
);
|
|
6752
6866
|
await fsp3.writeFile(backupFile, prev, "utf8");
|
|
6753
6867
|
backupState = "saved";
|
|
@@ -6762,22 +6876,22 @@ ${content}
|
|
|
6762
6876
|
backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
|
|
6763
6877
|
}
|
|
6764
6878
|
}
|
|
6765
|
-
const result = await saveTenantMeta(c.raw(),
|
|
6879
|
+
const result = await saveTenantMeta(c.raw(), path19, content);
|
|
6766
6880
|
const fmt = args.output ?? "json";
|
|
6767
|
-
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${
|
|
6881
|
+
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path19}
|
|
6768
6882
|
`);
|
|
6769
6883
|
const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
|
|
6770
|
-
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${
|
|
6771
|
-
` : 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 ${
|
|
6884
|
+
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${path19} --file ${backupFile}${connFlags(args)}
|
|
6885
|
+
` : 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 ${path19}${connFlags(args)}
|
|
6772
6886
|
` : ` \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
|
|
6773
|
-
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${
|
|
6887
|
+
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path19}${connFlags(args)}
|
|
6774
6888
|
`;
|
|
6775
6889
|
if (args.verify === false) {
|
|
6776
6890
|
process.stderr.write(
|
|
6777
6891
|
"\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
|
|
6778
6892
|
);
|
|
6779
6893
|
} else {
|
|
6780
|
-
const outcome = await verifyAfterWrite(c,
|
|
6894
|
+
const outcome = await verifyAfterWrite(c, path19);
|
|
6781
6895
|
if (outcome.status === "broken") {
|
|
6782
6896
|
const human = explainJacksonError(outcome.raw);
|
|
6783
6897
|
process.stderr.write(
|
|
@@ -6807,35 +6921,35 @@ ${content}
|
|
|
6807
6921
|
return;
|
|
6808
6922
|
} catch (e) {
|
|
6809
6923
|
if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
|
|
6810
|
-
|
|
6924
|
+
fail6(e, args);
|
|
6811
6925
|
}
|
|
6812
6926
|
}
|
|
6813
|
-
async function metaDeleteCommand(
|
|
6927
|
+
async function metaDeleteCommand(path19, args) {
|
|
6814
6928
|
try {
|
|
6815
6929
|
if (!args.yes) {
|
|
6816
|
-
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${
|
|
6930
|
+
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path19}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
|
|
6817
6931
|
if (!ok) {
|
|
6818
6932
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
6819
6933
|
process.exit(1);
|
|
6820
6934
|
}
|
|
6821
6935
|
}
|
|
6822
6936
|
const c = await client2(args);
|
|
6823
|
-
const result = await deleteTenantMeta(c.raw(),
|
|
6937
|
+
const result = await deleteTenantMeta(c.raw(), path19);
|
|
6824
6938
|
const fmt = args.output ?? "json";
|
|
6825
|
-
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${
|
|
6939
|
+
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path19}
|
|
6826
6940
|
`);
|
|
6827
6941
|
process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
|
|
6828
6942
|
process.exitCode = 0;
|
|
6829
6943
|
return;
|
|
6830
6944
|
} catch (e) {
|
|
6831
|
-
|
|
6945
|
+
fail6(e, args);
|
|
6832
6946
|
}
|
|
6833
6947
|
}
|
|
6834
|
-
async function metaValidateCommand(
|
|
6948
|
+
async function metaValidateCommand(path19, args) {
|
|
6835
6949
|
try {
|
|
6836
6950
|
if (!args.file) {
|
|
6837
|
-
throw new
|
|
6838
|
-
code:
|
|
6951
|
+
throw new CliError20({
|
|
6952
|
+
code: CliErrorCode19.MISSING_FLAG,
|
|
6839
6953
|
message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
|
|
6840
6954
|
});
|
|
6841
6955
|
}
|
|
@@ -6846,13 +6960,13 @@ async function metaValidateCommand(path18, args) {
|
|
|
6846
6960
|
process.stdin.on("end", () => resolve4(buf));
|
|
6847
6961
|
process.stdin.on("error", reject);
|
|
6848
6962
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6849
|
-
const result = validateMetaContent(
|
|
6963
|
+
const result = validateMetaContent(path19, content);
|
|
6850
6964
|
const fmt = args.output ?? "table";
|
|
6851
6965
|
if (fmt === "json" || fmt === "yaml") {
|
|
6852
6966
|
process.stdout.write(
|
|
6853
6967
|
formatObject18(
|
|
6854
6968
|
{
|
|
6855
|
-
path:
|
|
6969
|
+
path: path19,
|
|
6856
6970
|
kind: result.kind,
|
|
6857
6971
|
schemaKnown: result.schemaKnown,
|
|
6858
6972
|
schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
|
|
@@ -6864,7 +6978,7 @@ async function metaValidateCommand(path18, args) {
|
|
|
6864
6978
|
);
|
|
6865
6979
|
} else {
|
|
6866
6980
|
process.stdout.write(
|
|
6867
|
-
`\u{1F50E} ${
|
|
6981
|
+
`\u{1F50E} ${path19}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
|
|
6868
6982
|
`
|
|
6869
6983
|
);
|
|
6870
6984
|
process.stdout.write(
|
|
@@ -6875,7 +6989,7 @@ async function metaValidateCommand(path18, args) {
|
|
|
6875
6989
|
return;
|
|
6876
6990
|
} catch (e) {
|
|
6877
6991
|
if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
|
|
6878
|
-
|
|
6992
|
+
fail6(e, args);
|
|
6879
6993
|
}
|
|
6880
6994
|
}
|
|
6881
6995
|
|
|
@@ -6883,8 +6997,8 @@ async function metaValidateCommand(path18, args) {
|
|
|
6883
6997
|
init_exit();
|
|
6884
6998
|
init_auth_guard();
|
|
6885
6999
|
import * as crypto from "crypto";
|
|
6886
|
-
import * as
|
|
6887
|
-
import * as
|
|
7000
|
+
import * as fs6 from "fs/promises";
|
|
7001
|
+
import * as path6 from "path";
|
|
6888
7002
|
import {
|
|
6889
7003
|
buildMiniPreviewTargets,
|
|
6890
7004
|
buildMiniVerifyAgentReport,
|
|
@@ -7024,7 +7138,7 @@ async function workspaceBindCommand(workspaceKey, args) {
|
|
|
7024
7138
|
tenantId: args.tenant ?? client3?.tenantId,
|
|
7025
7139
|
endpoint: args.endpoint ?? client3?.endpoint
|
|
7026
7140
|
});
|
|
7027
|
-
await
|
|
7141
|
+
await fs6.mkdir(rootDir, { recursive: true });
|
|
7028
7142
|
await writeWorkspaceContext(rootDir, context);
|
|
7029
7143
|
writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
|
|
7030
7144
|
process.exitCode = 0;
|
|
@@ -7061,7 +7175,7 @@ async function workspaceCreateCommand(workspaceKey, args) {
|
|
|
7061
7175
|
tenantId: client3.tenantId,
|
|
7062
7176
|
endpoint: client3.endpoint
|
|
7063
7177
|
});
|
|
7064
|
-
await
|
|
7178
|
+
await fs6.mkdir(rootDir, { recursive: true });
|
|
7065
7179
|
await writeWorkspaceContext(rootDir, context);
|
|
7066
7180
|
writeWorkspaceCreateResult(
|
|
7067
7181
|
{
|
|
@@ -7099,7 +7213,7 @@ async function workspacePullCommand(args) {
|
|
|
7099
7213
|
tenantId: client3.tenantId ?? existing?.tenantId,
|
|
7100
7214
|
endpoint: client3.endpoint ?? existing?.endpoint
|
|
7101
7215
|
});
|
|
7102
|
-
await
|
|
7216
|
+
await fs6.mkdir(rootDir, { recursive: true });
|
|
7103
7217
|
await writeWorkspaceContext(rootDir, context);
|
|
7104
7218
|
const files = await listWorkspaceFiles(client3.raw(), workspaceKey, { pageSize: 5e3 });
|
|
7105
7219
|
const miniApps = detectRemoteMiniApps(files.data);
|
|
@@ -7109,7 +7223,7 @@ async function workspacePullCommand(args) {
|
|
|
7109
7223
|
http: client3.raw(),
|
|
7110
7224
|
appCode,
|
|
7111
7225
|
workspaceKey,
|
|
7112
|
-
targetDir:
|
|
7226
|
+
targetDir: path6.join(rootDir, MINI_APPS_DIR, appCode),
|
|
7113
7227
|
tenantId: client3.tenantId,
|
|
7114
7228
|
endpoint: client3.endpoint,
|
|
7115
7229
|
profile: args.profile ?? client3.profile,
|
|
@@ -7124,7 +7238,7 @@ async function workspacePullCommand(args) {
|
|
|
7124
7238
|
const rawRemoteByLocalPath = /* @__PURE__ */ new Map();
|
|
7125
7239
|
for (const file of rawFiles) {
|
|
7126
7240
|
const content = await loadWorkspaceFileContent(client3.raw(), file.id);
|
|
7127
|
-
const target =
|
|
7241
|
+
const target = path6.join(rootDir, content.relativePath);
|
|
7128
7242
|
await writeTextFile(target, content.content, !!args.force);
|
|
7129
7243
|
pulledRawFiles.push(content.relativePath);
|
|
7130
7244
|
rawRemoteByLocalPath.set(content.relativePath, file);
|
|
@@ -7175,7 +7289,7 @@ async function workspaceAddMiniCommand(appCode, args) {
|
|
|
7175
7289
|
const result = await initMiniAppProject({
|
|
7176
7290
|
appCode,
|
|
7177
7291
|
workspaceKey: context.workspaceKey,
|
|
7178
|
-
targetDir:
|
|
7292
|
+
targetDir: path6.join(rootDir, MINI_APPS_DIR, appCode),
|
|
7179
7293
|
name: args.name,
|
|
7180
7294
|
defaultSurface: parseSurface(args.surface),
|
|
7181
7295
|
templateKind,
|
|
@@ -7201,10 +7315,10 @@ async function workspaceRmCommand(relativePath, args) {
|
|
|
7201
7315
|
const rootDir = resolveRootDir(args.dir);
|
|
7202
7316
|
const context = await requireWorkspaceContext(rootDir);
|
|
7203
7317
|
const normalized = normalizeWorkspaceRmPath(relativePath);
|
|
7204
|
-
const absolutePath =
|
|
7318
|
+
const absolutePath = path6.join(rootDir, ...normalized.split("/"));
|
|
7205
7319
|
let stat;
|
|
7206
7320
|
try {
|
|
7207
|
-
stat = await
|
|
7321
|
+
stat = await fs6.lstat(absolutePath);
|
|
7208
7322
|
} catch (e) {
|
|
7209
7323
|
if (e.code !== "ENOENT") throw e;
|
|
7210
7324
|
stat = null;
|
|
@@ -7260,7 +7374,7 @@ async function workspaceRmCommand(relativePath, args) {
|
|
|
7260
7374
|
}
|
|
7261
7375
|
throw new Error(`workspace file not found locally or in the workspace: ${normalized}`);
|
|
7262
7376
|
}
|
|
7263
|
-
await
|
|
7377
|
+
await fs6.unlink(absolutePath);
|
|
7264
7378
|
const result = {
|
|
7265
7379
|
workspaceKey: context.workspaceKey,
|
|
7266
7380
|
file: normalized,
|
|
@@ -7534,7 +7648,7 @@ function removedMiniCommand() {
|
|
|
7534
7648
|
);
|
|
7535
7649
|
}
|
|
7536
7650
|
function resolveRootDir(dir) {
|
|
7537
|
-
return
|
|
7651
|
+
return path6.resolve(dir ?? ".");
|
|
7538
7652
|
}
|
|
7539
7653
|
function buildWorkspaceContext(args) {
|
|
7540
7654
|
return {
|
|
@@ -7550,7 +7664,7 @@ function buildWorkspaceContext(args) {
|
|
|
7550
7664
|
async function readWorkspaceContext(rootDir) {
|
|
7551
7665
|
try {
|
|
7552
7666
|
const parsed = JSON.parse(
|
|
7553
|
-
await
|
|
7667
|
+
await fs6.readFile(path6.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
|
|
7554
7668
|
);
|
|
7555
7669
|
if (parsed.kind !== WORKSPACE_CONTEXT_KIND || parsed.version !== WORKSPACE_CONTEXT_VERSION) {
|
|
7556
7670
|
throw new Error(`${WORKSPACE_CONTEXT_FILE} is not an HCM workspace context`);
|
|
@@ -7579,26 +7693,26 @@ async function requireWorkspaceContext(rootDir) {
|
|
|
7579
7693
|
return context;
|
|
7580
7694
|
}
|
|
7581
7695
|
async function writeWorkspaceContext(rootDir, context) {
|
|
7582
|
-
await
|
|
7583
|
-
|
|
7696
|
+
await fs6.writeFile(
|
|
7697
|
+
path6.join(rootDir, WORKSPACE_CONTEXT_FILE),
|
|
7584
7698
|
JSON.stringify(context, null, 2) + "\n"
|
|
7585
7699
|
);
|
|
7586
7700
|
}
|
|
7587
7701
|
async function writeTextFile(file, content, force) {
|
|
7588
7702
|
try {
|
|
7589
|
-
await
|
|
7703
|
+
await fs6.access(file);
|
|
7590
7704
|
if (!force) throw new Error(`${file} already exists; use --force to overwrite`);
|
|
7591
7705
|
} catch (e) {
|
|
7592
7706
|
if (e.code !== "ENOENT") throw e;
|
|
7593
7707
|
}
|
|
7594
|
-
await
|
|
7595
|
-
await
|
|
7708
|
+
await fs6.mkdir(path6.dirname(file), { recursive: true });
|
|
7709
|
+
await fs6.writeFile(file, content);
|
|
7596
7710
|
}
|
|
7597
7711
|
async function readWorkspaceRawManifest(rootDir, context) {
|
|
7598
7712
|
try {
|
|
7599
7713
|
const parsed = JSON.parse(
|
|
7600
|
-
await
|
|
7601
|
-
|
|
7714
|
+
await fs6.readFile(
|
|
7715
|
+
path6.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_MANIFEST_FILE),
|
|
7602
7716
|
"utf-8"
|
|
7603
7717
|
)
|
|
7604
7718
|
);
|
|
@@ -7620,8 +7734,8 @@ async function readWorkspaceRawManifest(rootDir, context) {
|
|
|
7620
7734
|
}
|
|
7621
7735
|
}
|
|
7622
7736
|
async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath) {
|
|
7623
|
-
const stateDir =
|
|
7624
|
-
await
|
|
7737
|
+
const stateDir = path6.join(rootDir, WORKSPACE_STATE_DIR);
|
|
7738
|
+
await fs6.mkdir(stateDir, { recursive: true });
|
|
7625
7739
|
const snapshots = files.map(
|
|
7626
7740
|
(file) => ({
|
|
7627
7741
|
localPath: file.localPath,
|
|
@@ -7632,8 +7746,8 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
|
|
|
7632
7746
|
lastModified: remoteByLocalPath.get(file.localPath)?.lastModified
|
|
7633
7747
|
})
|
|
7634
7748
|
);
|
|
7635
|
-
await
|
|
7636
|
-
|
|
7749
|
+
await fs6.writeFile(
|
|
7750
|
+
path6.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
|
|
7637
7751
|
JSON.stringify(
|
|
7638
7752
|
{
|
|
7639
7753
|
version: WORKSPACE_CONTEXT_VERSION,
|
|
@@ -7649,10 +7763,10 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
|
|
|
7649
7763
|
);
|
|
7650
7764
|
}
|
|
7651
7765
|
async function writeWorkspaceRawManifest(rootDir, manifest2) {
|
|
7652
|
-
const stateDir =
|
|
7653
|
-
await
|
|
7654
|
-
await
|
|
7655
|
-
|
|
7766
|
+
const stateDir = path6.join(rootDir, WORKSPACE_STATE_DIR);
|
|
7767
|
+
await fs6.mkdir(stateDir, { recursive: true });
|
|
7768
|
+
await fs6.writeFile(
|
|
7769
|
+
path6.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
|
|
7656
7770
|
JSON.stringify(manifest2, null, 2) + "\n",
|
|
7657
7771
|
"utf8"
|
|
7658
7772
|
);
|
|
@@ -7664,10 +7778,10 @@ async function readWorkspaceRawLocalFiles(rootDir) {
|
|
|
7664
7778
|
return files;
|
|
7665
7779
|
}
|
|
7666
7780
|
async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
|
|
7667
|
-
const absoluteDir =
|
|
7781
|
+
const absoluteDir = path6.join(rootDir, relativeDir);
|
|
7668
7782
|
let entries;
|
|
7669
7783
|
try {
|
|
7670
|
-
entries = await
|
|
7784
|
+
entries = await fs6.readdir(absoluteDir, { withFileTypes: true });
|
|
7671
7785
|
} catch (e) {
|
|
7672
7786
|
if (e.code === "ENOENT") return;
|
|
7673
7787
|
throw e;
|
|
@@ -7675,14 +7789,14 @@ async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
|
|
|
7675
7789
|
for (const entry of entries) {
|
|
7676
7790
|
if (entry.isDirectory() && RAW_WORKSPACE_EXCLUDED_DIRS.has(entry.name)) continue;
|
|
7677
7791
|
if (entry.isFile() && RAW_WORKSPACE_EXCLUDED_FILES.has(entry.name)) continue;
|
|
7678
|
-
const localPath = normalizeRelativePath(
|
|
7679
|
-
const absolutePath =
|
|
7792
|
+
const localPath = normalizeRelativePath(path6.posix.join(toPosix(relativeDir), entry.name));
|
|
7793
|
+
const absolutePath = path6.join(rootDir, localPath);
|
|
7680
7794
|
if (entry.isDirectory()) {
|
|
7681
7795
|
await walkWorkspaceRawFiles(rootDir, localPath, files);
|
|
7682
7796
|
continue;
|
|
7683
7797
|
}
|
|
7684
7798
|
if (!entry.isFile()) continue;
|
|
7685
|
-
const content = await
|
|
7799
|
+
const content = await fs6.readFile(absolutePath, "utf-8");
|
|
7686
7800
|
files.push({
|
|
7687
7801
|
localPath,
|
|
7688
7802
|
absolutePath,
|
|
@@ -7864,15 +7978,15 @@ function workspaceRawConflict(entry, reason) {
|
|
|
7864
7978
|
};
|
|
7865
7979
|
}
|
|
7866
7980
|
async function discoverMiniApps(rootDir) {
|
|
7867
|
-
const appsRoot =
|
|
7981
|
+
const appsRoot = path6.join(rootDir, MINI_APPS_DIR);
|
|
7868
7982
|
let entries;
|
|
7869
7983
|
try {
|
|
7870
|
-
entries = await
|
|
7984
|
+
entries = await fs6.readdir(appsRoot, { withFileTypes: true });
|
|
7871
7985
|
} catch (e) {
|
|
7872
7986
|
if (e.code === "ENOENT") return [];
|
|
7873
7987
|
throw e;
|
|
7874
7988
|
}
|
|
7875
|
-
return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir:
|
|
7989
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir: path6.join(appsRoot, entry.name) })).sort((a, b) => a.appCode.localeCompare(b.appCode));
|
|
7876
7990
|
}
|
|
7877
7991
|
function detectRemoteMiniApps(files) {
|
|
7878
7992
|
const appCodes = /* @__PURE__ */ new Set();
|
|
@@ -8015,7 +8129,7 @@ function normalizeWorkspaceKey(value) {
|
|
|
8015
8129
|
return key2;
|
|
8016
8130
|
}
|
|
8017
8131
|
function normalizeWorkspaceRmPath(value) {
|
|
8018
|
-
if (
|
|
8132
|
+
if (path6.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
|
|
8019
8133
|
throw new Error("workspace rm path must be relative to the bound workspace");
|
|
8020
8134
|
}
|
|
8021
8135
|
const normalized = normalizeRelativePath(value);
|
|
@@ -8037,7 +8151,7 @@ function normalizeRelativePath(value) {
|
|
|
8037
8151
|
return normalized;
|
|
8038
8152
|
}
|
|
8039
8153
|
function toPosix(value) {
|
|
8040
|
-
return value.split(
|
|
8154
|
+
return value.split(path6.sep).join("/");
|
|
8041
8155
|
}
|
|
8042
8156
|
function sha2563(content) {
|
|
8043
8157
|
return crypto.createHash("sha256").update(content, "utf-8").digest("hex");
|
|
@@ -8428,8 +8542,8 @@ init_exit();
|
|
|
8428
8542
|
import axios4 from "axios";
|
|
8429
8543
|
import {
|
|
8430
8544
|
AUTH_INFO_PATH,
|
|
8431
|
-
CliError as
|
|
8432
|
-
CliErrorCode as
|
|
8545
|
+
CliError as CliError21,
|
|
8546
|
+
CliErrorCode as CliErrorCode20,
|
|
8433
8547
|
formatObject as formatObject20,
|
|
8434
8548
|
fromAxiosError as fromAxiosError20,
|
|
8435
8549
|
loadEnv as loadEnv8,
|
|
@@ -8453,8 +8567,8 @@ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
|
|
|
8453
8567
|
const env3 = await loadEnv8(meta2.env);
|
|
8454
8568
|
const accessToken = await TokenStore3.forIdentity(name).getStoredAccessToken();
|
|
8455
8569
|
if (!accessToken) {
|
|
8456
|
-
throw new
|
|
8457
|
-
code:
|
|
8570
|
+
throw new CliError21({
|
|
8571
|
+
code: CliErrorCode20.AUTH_FAILED,
|
|
8458
8572
|
message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
|
|
8459
8573
|
context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
|
|
8460
8574
|
});
|
|
@@ -8511,8 +8625,8 @@ async function identityUse(name) {
|
|
|
8511
8625
|
try {
|
|
8512
8626
|
const meta2 = await loadIdentity4(name);
|
|
8513
8627
|
const env3 = await loadEnv8(meta2.env).catch(() => {
|
|
8514
|
-
throw new
|
|
8515
|
-
code:
|
|
8628
|
+
throw new CliError21({
|
|
8629
|
+
code: CliErrorCode20.IDENTITY_NOT_IN_ENV,
|
|
8516
8630
|
message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
|
|
8517
8631
|
});
|
|
8518
8632
|
});
|
|
@@ -8557,7 +8671,7 @@ import {
|
|
|
8557
8671
|
} from "@hcmai/sdk";
|
|
8558
8672
|
|
|
8559
8673
|
// src/commands/delivery.ts
|
|
8560
|
-
import { createHash as
|
|
8674
|
+
import { createHash as createHash5 } from "crypto";
|
|
8561
8675
|
var APPROVAL_BYPASS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "--force", "--auto-approve"]);
|
|
8562
8676
|
var CREDENTIAL_FLAGS = /* @__PURE__ */ new Set([
|
|
8563
8677
|
"--password",
|
|
@@ -9035,7 +9149,7 @@ function valuesAfterFlag(argv, flag) {
|
|
|
9035
9149
|
return values;
|
|
9036
9150
|
}
|
|
9037
9151
|
function sha2564(value) {
|
|
9038
|
-
return
|
|
9152
|
+
return createHash5("sha256").update(value).digest("hex");
|
|
9039
9153
|
}
|
|
9040
9154
|
function isPlainObject(value) {
|
|
9041
9155
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -9350,14 +9464,14 @@ function flagValue2(argv, flag) {
|
|
|
9350
9464
|
|
|
9351
9465
|
// src/commands/delivery-init.ts
|
|
9352
9466
|
init_exit();
|
|
9353
|
-
import { promises as
|
|
9354
|
-
import
|
|
9467
|
+
import { promises as fs8 } from "fs";
|
|
9468
|
+
import path8 from "path";
|
|
9355
9469
|
import { formatObject as formatObject22 } from "@hcmai/sdk";
|
|
9356
9470
|
|
|
9357
9471
|
// src/commands/delivery-mode-approval.ts
|
|
9358
9472
|
import { randomUUID } from "crypto";
|
|
9359
|
-
import { promises as
|
|
9360
|
-
import
|
|
9473
|
+
import { promises as fs7 } from "fs";
|
|
9474
|
+
import path7 from "path";
|
|
9361
9475
|
function requireControlledModeApproval(mode, approvedBy, reason) {
|
|
9362
9476
|
if (mode !== "controlled") return null;
|
|
9363
9477
|
const approver = approvedBy?.trim() ?? "";
|
|
@@ -9371,9 +9485,9 @@ function requireControlledModeApproval(mode, approvedBy, reason) {
|
|
|
9371
9485
|
}
|
|
9372
9486
|
async function setDeliveryModeWithReceipt(input) {
|
|
9373
9487
|
const approval = requireControlledModeApproval(input.mode, input.approvedBy, input.reason);
|
|
9374
|
-
const root =
|
|
9375
|
-
const projectFile =
|
|
9376
|
-
const content = await
|
|
9488
|
+
const root = path7.resolve(input.project);
|
|
9489
|
+
const projectFile = path7.join(root, ".hcm-delivery", "project.yml");
|
|
9490
|
+
const content = await fs7.readFile(projectFile, "utf8").catch((cause) => {
|
|
9377
9491
|
throw new Error(`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${projectFile}
|
|
9378
9492
|
\u4E0B\u4E00\u6B65\uFF1Ahcm chiron init`, {
|
|
9379
9493
|
cause
|
|
@@ -9384,12 +9498,12 @@ async function setDeliveryModeWithReceipt(input) {
|
|
|
9384
9498
|
if (Number.isNaN(changed.getTime())) throw new Error("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
|
|
9385
9499
|
let receiptFile = null;
|
|
9386
9500
|
if (approval) {
|
|
9387
|
-
const relativeDirectory =
|
|
9501
|
+
const relativeDirectory = path7.join("evidence", "delivery-mode");
|
|
9388
9502
|
await ensureReceiptDirectory(root);
|
|
9389
9503
|
const safeTime = changed.toISOString().replace(/[:.]/g, "-");
|
|
9390
9504
|
const id = (input.receiptId ?? randomUUID)();
|
|
9391
9505
|
if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E ID \u975E\u6CD5");
|
|
9392
|
-
receiptFile =
|
|
9506
|
+
receiptFile = path7.join(relativeDirectory, `${safeTime}-${id}.receipt.json`);
|
|
9393
9507
|
}
|
|
9394
9508
|
const receipt = {
|
|
9395
9509
|
schemaVersion: 1,
|
|
@@ -9406,10 +9520,10 @@ async function setDeliveryModeWithReceipt(input) {
|
|
|
9406
9520
|
reason: approval?.reason ?? null,
|
|
9407
9521
|
receiptFile
|
|
9408
9522
|
};
|
|
9409
|
-
await
|
|
9523
|
+
await fs7.writeFile(projectFile, update.content, "utf8");
|
|
9410
9524
|
if (receiptFile) {
|
|
9411
9525
|
try {
|
|
9412
|
-
await
|
|
9526
|
+
await fs7.writeFile(path7.join(root, receiptFile), `${JSON.stringify(receipt, null, 2)}
|
|
9413
9527
|
`, {
|
|
9414
9528
|
encoding: "utf8",
|
|
9415
9529
|
mode: 384,
|
|
@@ -9417,7 +9531,7 @@ async function setDeliveryModeWithReceipt(input) {
|
|
|
9417
9531
|
});
|
|
9418
9532
|
} catch (cause) {
|
|
9419
9533
|
try {
|
|
9420
|
-
await
|
|
9534
|
+
await fs7.writeFile(projectFile, content, "utf8");
|
|
9421
9535
|
} catch (rollbackCause) {
|
|
9422
9536
|
throw new Error(
|
|
9423
9537
|
`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF0C\u4E14 project.yml \u56DE\u6EDA\u5931\u8D25\uFF1A${String(rollbackCause.message)}`,
|
|
@@ -9430,24 +9544,24 @@ async function setDeliveryModeWithReceipt(input) {
|
|
|
9430
9544
|
return receipt;
|
|
9431
9545
|
}
|
|
9432
9546
|
async function ensureReceiptDirectory(root) {
|
|
9433
|
-
const evidenceDirectory =
|
|
9547
|
+
const evidenceDirectory = path7.join(root, "evidence");
|
|
9434
9548
|
await ensurePlainDirectory(evidenceDirectory, false);
|
|
9435
|
-
await ensurePlainDirectory(
|
|
9549
|
+
await ensurePlainDirectory(path7.join(evidenceDirectory, "delivery-mode"), true);
|
|
9436
9550
|
}
|
|
9437
9551
|
async function ensurePlainDirectory(directory, privateDirectory) {
|
|
9438
9552
|
let created = false;
|
|
9439
9553
|
try {
|
|
9440
|
-
await
|
|
9554
|
+
await fs7.mkdir(directory, { mode: privateDirectory ? 448 : 493 });
|
|
9441
9555
|
created = true;
|
|
9442
9556
|
} catch (cause) {
|
|
9443
9557
|
if (cause.code !== "EEXIST") throw cause;
|
|
9444
9558
|
}
|
|
9445
|
-
const stat = await
|
|
9559
|
+
const stat = await fs7.lstat(directory);
|
|
9446
9560
|
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
9447
9561
|
throw new Error(`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
|
|
9448
9562
|
}
|
|
9449
9563
|
if (privateDirectory || created) {
|
|
9450
|
-
await
|
|
9564
|
+
await fs7.chmod(directory, privateDirectory ? 448 : 493);
|
|
9451
9565
|
}
|
|
9452
9566
|
}
|
|
9453
9567
|
|
|
@@ -9471,11 +9585,11 @@ function renderProjectYml(environment, mode) {
|
|
|
9471
9585
|
async function deliveryModeCommand(args) {
|
|
9472
9586
|
try {
|
|
9473
9587
|
const environment = requireDeliveryModeEnvironment(args.env);
|
|
9474
|
-
const root =
|
|
9475
|
-
const file =
|
|
9588
|
+
const root = path8.resolve(args.project ?? ".");
|
|
9589
|
+
const file = path8.join(root, ".hcm-delivery", "project.yml");
|
|
9476
9590
|
let content;
|
|
9477
9591
|
try {
|
|
9478
|
-
content = await
|
|
9592
|
+
content = await fs8.readFile(file, "utf8");
|
|
9479
9593
|
} catch {
|
|
9480
9594
|
throw new Error(
|
|
9481
9595
|
`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
|
|
@@ -9536,11 +9650,11 @@ function requireDeliveryModeEnvironment(envFlag) {
|
|
|
9536
9650
|
// src/commands/chiron-init.ts
|
|
9537
9651
|
init_auth_guard();
|
|
9538
9652
|
init_exit();
|
|
9539
|
-
import { promises as
|
|
9540
|
-
import
|
|
9653
|
+
import { promises as fs12 } from "fs";
|
|
9654
|
+
import path11 from "path";
|
|
9541
9655
|
import {
|
|
9542
|
-
CliError as
|
|
9543
|
-
CliErrorCode as
|
|
9656
|
+
CliError as CliError22,
|
|
9657
|
+
CliErrorCode as CliErrorCode21,
|
|
9544
9658
|
HcmClient as HcmClient21,
|
|
9545
9659
|
fetchReconIdentity,
|
|
9546
9660
|
formatObject as formatObject23,
|
|
@@ -9702,7 +9816,7 @@ function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
|
|
|
9702
9816
|
}
|
|
9703
9817
|
|
|
9704
9818
|
// src/commands/delivery-project-scaffold.ts
|
|
9705
|
-
import { promises as
|
|
9819
|
+
import { promises as fs9 } from "fs";
|
|
9706
9820
|
var AGENT_BEGIN = "<!-- hcm-delivery-project:begin -->";
|
|
9707
9821
|
var AGENT_END = "<!-- hcm-delivery-project:end -->";
|
|
9708
9822
|
var GITIGNORE_BEGIN = "# >>> hcm delivery local state >>>";
|
|
@@ -9724,12 +9838,12 @@ async function mergeManagedFile(file, merge, result, relative2) {
|
|
|
9724
9838
|
result.preserved.push(relative2);
|
|
9725
9839
|
return;
|
|
9726
9840
|
}
|
|
9727
|
-
await
|
|
9841
|
+
await fs9.writeFile(file, next, { encoding: "utf8", mode: 420 });
|
|
9728
9842
|
(existing === null ? result.created : result.updated).push(relative2);
|
|
9729
9843
|
}
|
|
9730
9844
|
async function writeIfAbsent(file, content, result, relative2, mode = 420) {
|
|
9731
9845
|
try {
|
|
9732
|
-
await
|
|
9846
|
+
await fs9.writeFile(file, content, { encoding: "utf8", mode, flag: "wx" });
|
|
9733
9847
|
result.created.push(relative2);
|
|
9734
9848
|
return true;
|
|
9735
9849
|
} catch (cause) {
|
|
@@ -9740,8 +9854,8 @@ async function writeIfAbsent(file, content, result, relative2, mode = 420) {
|
|
|
9740
9854
|
}
|
|
9741
9855
|
}
|
|
9742
9856
|
async function ensureDirectory(directory) {
|
|
9743
|
-
await
|
|
9744
|
-
const stat = await
|
|
9857
|
+
await fs9.mkdir(directory, { recursive: true });
|
|
9858
|
+
const stat = await fs9.lstat(directory);
|
|
9745
9859
|
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
9746
9860
|
throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
|
|
9747
9861
|
}
|
|
@@ -9749,14 +9863,14 @@ async function ensureDirectory(directory) {
|
|
|
9749
9863
|
async function readRegularFile(file) {
|
|
9750
9864
|
try {
|
|
9751
9865
|
await assertRegularFile(file);
|
|
9752
|
-
return await
|
|
9866
|
+
return await fs9.readFile(file, "utf8");
|
|
9753
9867
|
} catch (cause) {
|
|
9754
9868
|
if (cause.code === "ENOENT") return null;
|
|
9755
9869
|
throw cause;
|
|
9756
9870
|
}
|
|
9757
9871
|
}
|
|
9758
9872
|
async function assertRegularFile(file) {
|
|
9759
|
-
const stat = await
|
|
9873
|
+
const stat = await fs9.lstat(file);
|
|
9760
9874
|
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
9761
9875
|
throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${file}`);
|
|
9762
9876
|
}
|
|
@@ -9780,17 +9894,17 @@ function upsertBlock(existing, begin, end, block) {
|
|
|
9780
9894
|
}
|
|
9781
9895
|
|
|
9782
9896
|
// src/commands/chiron-project.ts
|
|
9783
|
-
import { promises as
|
|
9897
|
+
import { promises as fs11 } from "fs";
|
|
9784
9898
|
import os5 from "os";
|
|
9785
|
-
import
|
|
9899
|
+
import path10 from "path";
|
|
9786
9900
|
import { spawnSync } from "child_process";
|
|
9787
9901
|
import { hcmConfigDir, listEnvs as listEnvs3, listIdentities as listIdentities4, loadEnv as loadEnv9, loadGlobalConfig as loadGlobalConfig9 } from "@hcmai/sdk";
|
|
9788
9902
|
|
|
9789
9903
|
// src/jira/client.ts
|
|
9790
9904
|
import { execFileSync } from "child_process";
|
|
9791
|
-
import { promises as
|
|
9905
|
+
import { promises as fs10 } from "fs";
|
|
9792
9906
|
import os4 from "os";
|
|
9793
|
-
import
|
|
9907
|
+
import path9 from "path";
|
|
9794
9908
|
|
|
9795
9909
|
// src/internal-endpoints.ts
|
|
9796
9910
|
var env = (key2, fallback) => {
|
|
@@ -9808,13 +9922,13 @@ var repoIssueUrl = (repo, number) => `${CNB_ORIGIN}/${repo}/-/issues/${number}`;
|
|
|
9808
9922
|
var CNB_FAVICON_URL = `${CNB_ORIGIN}/favicon.ico`;
|
|
9809
9923
|
|
|
9810
9924
|
// src/jira/client.ts
|
|
9811
|
-
var JIRA_TOKEN_FILE = () => process.env.JIRA_TOKEN_FILE ||
|
|
9925
|
+
var JIRA_TOKEN_FILE = () => process.env.JIRA_TOKEN_FILE || path9.join(os4.homedir(), ".config", "hcm", "jira-token");
|
|
9812
9926
|
async function jiraTokenSource() {
|
|
9813
9927
|
if (process.env.JIRA_TOKEN?.trim()) return { token: process.env.JIRA_TOKEN.trim(), from: "\u73AF\u5883\u53D8\u91CF JIRA_TOKEN" };
|
|
9814
9928
|
const file = JIRA_TOKEN_FILE();
|
|
9815
9929
|
try {
|
|
9816
|
-
const stat = await
|
|
9817
|
-
const value = (await
|
|
9930
|
+
const stat = await fs10.stat(file);
|
|
9931
|
+
const value = (await fs10.readFile(file, "utf8")).trim();
|
|
9818
9932
|
if (value) {
|
|
9819
9933
|
if (stat.mode & 63) process.stderr.write(`[jira] \u8B66\u544A\uFF1A${file} \u5BF9\u5176\u4ED6\u7528\u6237\u53EF\u8BFB\uFF08chmod 600 \u6536\u7D27\uFF09
|
|
9820
9934
|
`);
|
|
@@ -10090,13 +10204,13 @@ function mergeChironAgentInstructions(existing) {
|
|
|
10090
10204
|
return upsertBlock(existing, AGENT_BEGIN, AGENT_END, renderChironAgentInstructions().trimEnd());
|
|
10091
10205
|
}
|
|
10092
10206
|
function caseLibraryDir() {
|
|
10093
|
-
return
|
|
10207
|
+
return path10.join(hcmConfigDir(), CASES_MCP_NAME);
|
|
10094
10208
|
}
|
|
10095
10209
|
function codexConfigFile() {
|
|
10096
|
-
return
|
|
10210
|
+
return path10.join(process.env.HOME ?? os5.homedir(), ".codex", "config.toml");
|
|
10097
10211
|
}
|
|
10098
10212
|
function renderCodexMcpSection(repo, envName, binPath = process.env.PATH ?? "") {
|
|
10099
|
-
const server =
|
|
10213
|
+
const server = path10.join(repo, "mcp", "server.mjs");
|
|
10100
10214
|
const env3 = [
|
|
10101
10215
|
`CASES_REPO = ${JSON.stringify(repo)}`,
|
|
10102
10216
|
`HCM_ENV = ${JSON.stringify(envName)}`,
|
|
@@ -10159,13 +10273,13 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
|
|
|
10159
10273
|
const repo = paths.repo ?? caseLibraryDir();
|
|
10160
10274
|
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
10161
10275
|
const status = { ok: false, repo, step: "present", serverInstalled: false, codexWired: false };
|
|
10162
|
-
const hasGit = await exists2(
|
|
10276
|
+
const hasGit = await exists2(path10.join(repo, ".git"));
|
|
10163
10277
|
if (hasGit) {
|
|
10164
10278
|
const pull = deps.git(["pull", "--ff-only", "--quiet"], repo);
|
|
10165
10279
|
status.step = pull.status === 0 ? "updated" : "present";
|
|
10166
10280
|
if (pull.status !== 0) status.reason = `\u66F4\u65B0\u5931\u8D25\uFF0C\u6CBF\u7528\u672C\u5730\u7248\u672C\uFF1A${firstLine(pull.stderr, pull.error)}`;
|
|
10167
10281
|
} else {
|
|
10168
|
-
await
|
|
10282
|
+
await fs11.mkdir(path10.dirname(repo), { recursive: true });
|
|
10169
10283
|
const clone = deps.git(["clone", "--depth", "1", "--quiet", CASES_REPO_URL, repo]);
|
|
10170
10284
|
if (clone.status !== 0) {
|
|
10171
10285
|
status.step = "clone-failed";
|
|
@@ -10174,13 +10288,13 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
|
|
|
10174
10288
|
}
|
|
10175
10289
|
status.step = "cloned";
|
|
10176
10290
|
}
|
|
10177
|
-
const mcpDir =
|
|
10178
|
-
if (!await exists2(
|
|
10291
|
+
const mcpDir = path10.join(repo, "mcp");
|
|
10292
|
+
if (!await exists2(path10.join(mcpDir, "server.mjs"))) {
|
|
10179
10293
|
status.step = "install-failed";
|
|
10180
10294
|
status.reason = `\u6848\u4F8B\u5E93\u91CC\u6CA1\u6709 mcp/server.mjs\uFF1A${mcpDir}`;
|
|
10181
10295
|
return status;
|
|
10182
10296
|
}
|
|
10183
|
-
if (!await exists2(
|
|
10297
|
+
if (!await exists2(path10.join(mcpDir, "node_modules", "@modelcontextprotocol"))) {
|
|
10184
10298
|
const install = deps.npmInstall(mcpDir);
|
|
10185
10299
|
if (install.status !== 0) {
|
|
10186
10300
|
status.step = "install-failed";
|
|
@@ -10189,10 +10303,10 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
|
|
|
10189
10303
|
}
|
|
10190
10304
|
}
|
|
10191
10305
|
status.serverInstalled = true;
|
|
10192
|
-
await
|
|
10193
|
-
const existing = await
|
|
10306
|
+
await fs11.mkdir(path10.dirname(codexConfig), { recursive: true });
|
|
10307
|
+
const existing = await fs11.readFile(codexConfig, "utf8").catch(() => "");
|
|
10194
10308
|
const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
|
|
10195
|
-
if (next !== existing) await
|
|
10309
|
+
if (next !== existing) await fs11.writeFile(codexConfig, next, "utf8");
|
|
10196
10310
|
status.codexWired = true;
|
|
10197
10311
|
status.ok = true;
|
|
10198
10312
|
return status;
|
|
@@ -10200,9 +10314,9 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
|
|
|
10200
10314
|
async function inspectCaseLibrary(paths = {}) {
|
|
10201
10315
|
const repo = paths.repo ?? caseLibraryDir();
|
|
10202
10316
|
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
10203
|
-
const cloned = await exists2(
|
|
10204
|
-
const serverInstalled = cloned && await exists2(
|
|
10205
|
-
const codexWired = codexConfigHasCases(await
|
|
10317
|
+
const cloned = await exists2(path10.join(repo, ".git"));
|
|
10318
|
+
const serverInstalled = cloned && await exists2(path10.join(repo, "mcp", "server.mjs")) && await exists2(path10.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
|
|
10319
|
+
const codexWired = codexConfigHasCases(await fs11.readFile(codexConfig, "utf8").catch(() => ""));
|
|
10206
10320
|
return { repo, cloned, serverInstalled, codexWired };
|
|
10207
10321
|
}
|
|
10208
10322
|
function firstLine(stderr, error) {
|
|
@@ -10244,7 +10358,7 @@ async function inspectJira() {
|
|
|
10244
10358
|
}
|
|
10245
10359
|
async function exists2(file) {
|
|
10246
10360
|
try {
|
|
10247
|
-
await
|
|
10361
|
+
await fs11.access(file);
|
|
10248
10362
|
return true;
|
|
10249
10363
|
} catch {
|
|
10250
10364
|
return false;
|
|
@@ -10268,7 +10382,7 @@ var defaultChironInitDeps = {
|
|
|
10268
10382
|
all: true,
|
|
10269
10383
|
target: "codex",
|
|
10270
10384
|
env: envName,
|
|
10271
|
-
dir:
|
|
10385
|
+
dir: path11.join(root, SKILLS_DIR),
|
|
10272
10386
|
output: "table"
|
|
10273
10387
|
});
|
|
10274
10388
|
} finally {
|
|
@@ -10285,22 +10399,22 @@ async function resolveLoggedInEnv() {
|
|
|
10285
10399
|
const name = g.activeEnv;
|
|
10286
10400
|
const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
|
|
10287
10401
|
if (!name) {
|
|
10288
|
-
throw new
|
|
10289
|
-
code:
|
|
10402
|
+
throw new CliError22({
|
|
10403
|
+
code: CliErrorCode21.ENV_NOT_FOUND,
|
|
10290
10404
|
message: `\u8FD8\u6CA1\u767B\u5F55\u4EFB\u4F55\u73AF\u5883\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10291
10405
|
});
|
|
10292
10406
|
}
|
|
10293
10407
|
const config2 = await loadEnv10(name).catch(() => null);
|
|
10294
10408
|
if (!config2?.endpoint) {
|
|
10295
|
-
throw new
|
|
10296
|
-
code:
|
|
10409
|
+
throw new CliError22({
|
|
10410
|
+
code: CliErrorCode21.ENV_NOT_FOUND,
|
|
10297
10411
|
message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10298
10412
|
});
|
|
10299
10413
|
}
|
|
10300
10414
|
const identities = await listIdentities5(name).catch(() => []);
|
|
10301
10415
|
if (identities.length === 0) {
|
|
10302
|
-
throw new
|
|
10303
|
-
code:
|
|
10416
|
+
throw new CliError22({
|
|
10417
|
+
code: CliErrorCode21.IDENTITY_NOT_FOUND,
|
|
10304
10418
|
message: `\u73AF\u5883 '${name}'\uFF08${config2.endpoint}\uFF09\u8FD8\u6CA1\u6709\u767B\u5F55\u8EAB\u4EFD\u3002\u5148\u6267\u884C\uFF1Ahcm login ${config2.endpoint} --code <\u914D\u5BF9\u7801>`
|
|
10305
10419
|
});
|
|
10306
10420
|
}
|
|
@@ -10309,57 +10423,57 @@ async function resolveLoggedInEnv() {
|
|
|
10309
10423
|
}
|
|
10310
10424
|
async function scaffoldChironProject(root, env3, envName) {
|
|
10311
10425
|
const result = { created: [], updated: [], preserved: [] };
|
|
10312
|
-
const envFile =
|
|
10313
|
-
const existing = await
|
|
10426
|
+
const envFile = path11.join(root, ENV_FILE);
|
|
10427
|
+
const existing = await fs12.readFile(envFile, "utf8").catch(() => null);
|
|
10314
10428
|
if (existing !== null) {
|
|
10315
10429
|
const recorded = parseEnvYaml(existing);
|
|
10316
10430
|
if (recorded.endpoint !== env3.endpoint) {
|
|
10317
|
-
throw new
|
|
10318
|
-
code:
|
|
10431
|
+
throw new CliError22({
|
|
10432
|
+
code: CliErrorCode21.INVALID_ARGUMENT,
|
|
10319
10433
|
message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env3.endpoint}\uFF08env '${envName}'\uFF09\u3002
|
|
10320
10434
|
\u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
|
|
10321
10435
|
\u8981\u628A\u9879\u76EE\u6539\u5230\u4F60\u767B\u5F55\u7684\u73AF\u5883\uFF1A\u5220\u6389 ${ENV_FILE} \u540E\u91CD\u8DD1\uFF08\u8FD9\u4F1A\u5F71\u54CD\u6240\u6709\u534F\u4F5C\u8005\uFF0C\u5148\u8DDF\u8D1F\u8D23\u4EBA\u786E\u8BA4\uFF09`
|
|
10322
10436
|
});
|
|
10323
10437
|
}
|
|
10324
10438
|
if (recorded.tenant !== env3.tenant) {
|
|
10325
|
-
throw new
|
|
10326
|
-
code:
|
|
10439
|
+
throw new CliError22({
|
|
10440
|
+
code: CliErrorCode21.INVALID_ARGUMENT,
|
|
10327
10441
|
message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env3.tenant}\u3002
|
|
10328
10442
|
\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env3.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
|
|
10329
10443
|
});
|
|
10330
10444
|
}
|
|
10331
10445
|
result.preserved.push(ENV_FILE);
|
|
10332
10446
|
} else {
|
|
10333
|
-
await
|
|
10447
|
+
await fs12.writeFile(envFile, renderEnvYaml(env3), { encoding: "utf8", mode: 420, flag: "wx" });
|
|
10334
10448
|
result.created.push(ENV_FILE);
|
|
10335
10449
|
}
|
|
10336
10450
|
for (const directory of CHIRON_PROJECT_DIRECTORIES) {
|
|
10337
|
-
const absolute =
|
|
10451
|
+
const absolute = path11.join(root, directory);
|
|
10338
10452
|
await ensureDirectory(absolute);
|
|
10339
|
-
await writeIfAbsent(
|
|
10453
|
+
await writeIfAbsent(path11.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
|
|
10340
10454
|
}
|
|
10341
|
-
const deliveryDir =
|
|
10455
|
+
const deliveryDir = path11.join(root, ".hcm-delivery");
|
|
10342
10456
|
await ensureDirectory(deliveryDir);
|
|
10343
10457
|
await writeIfAbsent(
|
|
10344
|
-
|
|
10458
|
+
path11.join(deliveryDir, "project.yml"),
|
|
10345
10459
|
renderProjectYml(envName, "plan-only"),
|
|
10346
10460
|
result,
|
|
10347
10461
|
".hcm-delivery/project.yml"
|
|
10348
10462
|
);
|
|
10349
|
-
const pageAcceptanceFile =
|
|
10463
|
+
const pageAcceptanceFile = path11.join(root, "page-acceptance.sh");
|
|
10350
10464
|
const created = await writeIfAbsent(pageAcceptanceFile, renderPageAcceptanceSh("evidence"), result, "page-acceptance.sh", 493);
|
|
10351
|
-
if (created) await
|
|
10352
|
-
await mergeManagedFile(
|
|
10353
|
-
await mergeManagedFile(
|
|
10354
|
-
await mergeManagedFile(
|
|
10465
|
+
if (created) await fs12.chmod(pageAcceptanceFile, 493);
|
|
10466
|
+
await mergeManagedFile(path11.join(root, "AGENTS.md"), mergeChironAgentInstructions, result, "AGENTS.md");
|
|
10467
|
+
await mergeManagedFile(path11.join(root, "CLAUDE.md"), mergeChironAgentInstructions, result, "CLAUDE.md");
|
|
10468
|
+
await mergeManagedFile(path11.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
|
|
10355
10469
|
return result;
|
|
10356
10470
|
}
|
|
10357
10471
|
async function runChironInit(args, deps = defaultChironInitDeps) {
|
|
10358
|
-
const root =
|
|
10472
|
+
const root = path11.resolve(args.project ?? ".");
|
|
10359
10473
|
const { name, env: env3, identity: identity2 } = await resolveLoggedInEnv();
|
|
10360
10474
|
if (isTempEnv3(name)) {
|
|
10361
|
-
throw new
|
|
10362
|
-
code:
|
|
10475
|
+
throw new CliError22({
|
|
10476
|
+
code: CliErrorCode21.INVALID_ARGUMENT,
|
|
10363
10477
|
message: `\u5F53\u524D\u662F\u4E34\u65F6\u73AF\u5883\uFF08${env3.endpoint}\uFF09\uFF0C\u8FD8\u6CA1\u6709\u540D\u5B57\u3002\u9879\u76EE\u8981\u7ED1\u4E00\u4E2A\u7A33\u5B9A\u7684 env\uFF0C\u5426\u5219\u4E0B\u4E00\u6B21 hcm login --code \u8986\u76D6\u5B83\u4E4B\u540E\uFF0C\u9879\u76EE\u4ED3\u8BB0\u7684\u73AF\u5883\u5C31\u5BF9\u4E0D\u4E0A\u4E86\u3002`,
|
|
10364
10478
|
context: { nextStep: `\u5148\u7ED9\u5B83\u8D77\u4E2A\u540D\u5B57\uFF1Ahcm env save <name>\uFF0C\u7136\u540E\u91CD\u8DD1 hcm chiron init` }
|
|
10365
10479
|
});
|
|
@@ -10426,11 +10540,11 @@ async function chironInitCommand(args, deps) {
|
|
|
10426
10540
|
// src/commands/chiron-doctor.ts
|
|
10427
10541
|
init_auth_guard();
|
|
10428
10542
|
init_exit();
|
|
10429
|
-
import { promises as
|
|
10430
|
-
import
|
|
10543
|
+
import { promises as fs13 } from "fs";
|
|
10544
|
+
import path12 from "path";
|
|
10431
10545
|
import {
|
|
10432
10546
|
HcmClient as HcmClient22,
|
|
10433
|
-
CliError as
|
|
10547
|
+
CliError as CliError23,
|
|
10434
10548
|
fetchReconIdentity as fetchReconIdentity2,
|
|
10435
10549
|
formatObject as formatObject24,
|
|
10436
10550
|
httpProbe as httpProbe2,
|
|
@@ -10452,9 +10566,9 @@ var defaultDeps = {
|
|
|
10452
10566
|
inspectJira: () => inspectJira()
|
|
10453
10567
|
};
|
|
10454
10568
|
async function runChironDoctor(args, deps = defaultDeps) {
|
|
10455
|
-
const root =
|
|
10569
|
+
const root = path12.resolve(args.project ?? ".");
|
|
10456
10570
|
const report = { ok: false, project: root, env: null, envName: null, lines: [] };
|
|
10457
|
-
const envText = await
|
|
10571
|
+
const envText = await fs13.readFile(path12.join(root, ENV_FILE), "utf8").catch(() => null);
|
|
10458
10572
|
if (envText === null) {
|
|
10459
10573
|
report.lines.push({
|
|
10460
10574
|
item: "\u767B\u5F55",
|
|
@@ -10499,12 +10613,12 @@ async function runChironDoctor(args, deps = defaultDeps) {
|
|
|
10499
10613
|
});
|
|
10500
10614
|
}
|
|
10501
10615
|
} catch (e) {
|
|
10502
|
-
const msg = e instanceof
|
|
10616
|
+
const msg = e instanceof CliError23 ? e.message : e.message;
|
|
10503
10617
|
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env3.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
|
|
10504
10618
|
}
|
|
10505
10619
|
}
|
|
10506
10620
|
const skillsLine = async () => {
|
|
10507
|
-
const state = await readSkillsState(
|
|
10621
|
+
const state = await readSkillsState(path12.join(root, SKILLS_DIR));
|
|
10508
10622
|
if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron doctor --fix\uFF08\u6216 hcm chiron init\uFF09" };
|
|
10509
10623
|
const count = Object.keys(state.skills).length;
|
|
10510
10624
|
if (state.endpoint && normalizeOrigin(state.endpoint) !== env3.endpoint) {
|
|
@@ -10570,8 +10684,8 @@ async function chironDoctorCommand(args, deps) {
|
|
|
10570
10684
|
// src/commands/chiron-test.ts
|
|
10571
10685
|
init_exit();
|
|
10572
10686
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
10573
|
-
import { promises as
|
|
10574
|
-
import
|
|
10687
|
+
import { promises as fs14 } from "fs";
|
|
10688
|
+
import path13 from "path";
|
|
10575
10689
|
import yaml2 from "js-yaml";
|
|
10576
10690
|
import { formatObject as formatObject25 } from "@hcmai/sdk";
|
|
10577
10691
|
|
|
@@ -10772,7 +10886,7 @@ var defaultDeps2 = {
|
|
|
10772
10886
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
10773
10887
|
},
|
|
10774
10888
|
readXlsx: (file) => xlsxRows(file),
|
|
10775
|
-
readText: (file) =>
|
|
10889
|
+
readText: (file) => fs14.readFile(file, "utf8")
|
|
10776
10890
|
};
|
|
10777
10891
|
async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
|
|
10778
10892
|
const results = [];
|
|
@@ -10825,7 +10939,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
|
|
|
10825
10939
|
continue;
|
|
10826
10940
|
}
|
|
10827
10941
|
if (c.file) {
|
|
10828
|
-
const file =
|
|
10942
|
+
const file = path13.resolve(root, fill(c.file));
|
|
10829
10943
|
const want = c.expect ?? {};
|
|
10830
10944
|
const bad = [];
|
|
10831
10945
|
if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
|
|
@@ -10841,7 +10955,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
|
|
|
10841
10955
|
results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
|
|
10842
10956
|
continue;
|
|
10843
10957
|
}
|
|
10844
|
-
const out =
|
|
10958
|
+
const out = path13.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
|
|
10845
10959
|
const argv = ["--path", fill(c.page), "--out", out];
|
|
10846
10960
|
if (opts.env) argv.push("--env", opts.env);
|
|
10847
10961
|
const as = c.as ?? opts.as;
|
|
@@ -10857,12 +10971,12 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
|
|
|
10857
10971
|
return results;
|
|
10858
10972
|
}
|
|
10859
10973
|
async function loadCases(target) {
|
|
10860
|
-
const stat = await
|
|
10861
|
-
const files = stat.isDirectory() ? (await
|
|
10974
|
+
const stat = await fs14.stat(target);
|
|
10975
|
+
const files = stat.isDirectory() ? (await fs14.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path13.join(target, f)) : [target];
|
|
10862
10976
|
const out = [];
|
|
10863
10977
|
for (const f of files) {
|
|
10864
|
-
const spec = yaml2.load(await
|
|
10865
|
-
assertUsableSpec(spec,
|
|
10978
|
+
const spec = yaml2.load(await fs14.readFile(f, "utf8"));
|
|
10979
|
+
assertUsableSpec(spec, path13.basename(f));
|
|
10866
10980
|
out.push({ file: f, spec });
|
|
10867
10981
|
}
|
|
10868
10982
|
if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
|
|
@@ -10870,15 +10984,15 @@ async function loadCases(target) {
|
|
|
10870
10984
|
}
|
|
10871
10985
|
async function chironTestCommand(target, args, deps) {
|
|
10872
10986
|
try {
|
|
10873
|
-
const root =
|
|
10874
|
-
const where =
|
|
10987
|
+
const root = path13.resolve(args.project ?? ".");
|
|
10988
|
+
const where = path13.resolve(root, target ?? "tests");
|
|
10875
10989
|
const cases = await loadCases(where);
|
|
10876
10990
|
const report = [];
|
|
10877
10991
|
let failed2 = 0;
|
|
10878
10992
|
for (const { file, spec } of cases) {
|
|
10879
10993
|
const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
|
|
10880
10994
|
failed2 += results.filter((r) => r.verdict === "fail").length;
|
|
10881
|
-
report.push({ case: spec.name, file:
|
|
10995
|
+
report.push({ case: spec.name, file: path13.relative(root, file), results });
|
|
10882
10996
|
}
|
|
10883
10997
|
const fmt = args.output ?? "table";
|
|
10884
10998
|
if (fmt === "json" || fmt === "yaml") {
|
|
@@ -11774,9 +11888,9 @@ import {
|
|
|
11774
11888
|
loadProtocolFacts,
|
|
11775
11889
|
scan
|
|
11776
11890
|
} from "@hcmai/sdk";
|
|
11777
|
-
import * as
|
|
11891
|
+
import * as path14 from "path";
|
|
11778
11892
|
function renderGate0(result, skillRoot) {
|
|
11779
|
-
const where = skillRoot ? `\uFF08${
|
|
11893
|
+
const where = skillRoot ? `\uFF08${path14.resolve(skillRoot)}\uFF09` : "";
|
|
11780
11894
|
const lines = [
|
|
11781
11895
|
`\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`
|
|
11782
11896
|
];
|
|
@@ -11889,7 +12003,7 @@ import {
|
|
|
11889
12003
|
writeRisk
|
|
11890
12004
|
} from "@hcmai/sdk";
|
|
11891
12005
|
import { existsSync as existsSync3 } from "fs";
|
|
11892
|
-
import * as
|
|
12006
|
+
import * as path15 from "path";
|
|
11893
12007
|
function premise(message, hint = "") {
|
|
11894
12008
|
process.stderr.write(message + (hint ? `
|
|
11895
12009
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -11916,13 +12030,13 @@ async function runSeedPlan(args, client3) {
|
|
|
11916
12030
|
const reconDir = candidates[0].reconDir;
|
|
11917
12031
|
if (candidates.length > 1) {
|
|
11918
12032
|
process.stderr.write(
|
|
11919
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
12033
|
+
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path15.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path15.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
|
|
11920
12034
|
);
|
|
11921
12035
|
}
|
|
11922
12036
|
const round = inspectRound3(reconDir);
|
|
11923
12037
|
process.stderr.write(roundWarning(round));
|
|
11924
12038
|
const baseline = {
|
|
11925
|
-
path: `${
|
|
12039
|
+
path: `${path15.basename(path15.dirname(reconDir))}/${path15.basename(reconDir)}`,
|
|
11926
12040
|
roundId: round.roundId ?? null
|
|
11927
12041
|
};
|
|
11928
12042
|
let exemptions = null;
|
|
@@ -12184,7 +12298,7 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
12184
12298
|
// src/commands/delivery-seed-find.ts
|
|
12185
12299
|
import { existsSync as existsSync4 } from "fs";
|
|
12186
12300
|
import { readFileSync as readFileSync8 } from "fs";
|
|
12187
|
-
import * as
|
|
12301
|
+
import * as path16 from "path";
|
|
12188
12302
|
import {
|
|
12189
12303
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
12190
12304
|
ValueHints,
|
|
@@ -12198,10 +12312,10 @@ import {
|
|
|
12198
12312
|
valuesRoundCaveat
|
|
12199
12313
|
} from "@hcmai/sdk";
|
|
12200
12314
|
function provenance(chosenReconDir, others) {
|
|
12201
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
12315
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path16.basename(chosenReconDir)}\`
|
|
12202
12316
|
`;
|
|
12203
12317
|
if (others.length > 0) {
|
|
12204
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
12318
|
+
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path16.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
|
|
12205
12319
|
}
|
|
12206
12320
|
return `${line}
|
|
12207
12321
|
`;
|
|
@@ -12538,7 +12652,7 @@ import {
|
|
|
12538
12652
|
runTriageRound
|
|
12539
12653
|
} from "@hcmai/sdk";
|
|
12540
12654
|
import { mkdirSync, readFileSync as readFileSync10, writeFileSync as writeFileSync2 } from "fs";
|
|
12541
|
-
import * as
|
|
12655
|
+
import * as path17 from "path";
|
|
12542
12656
|
var DEFAULT_CAPABILITIES3 = "default";
|
|
12543
12657
|
function premise4(message, hint) {
|
|
12544
12658
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -12574,8 +12688,8 @@ function renderProblems(rows) {
|
|
|
12574
12688
|
`;
|
|
12575
12689
|
}
|
|
12576
12690
|
function writeTriageArtifact(outDir, body) {
|
|
12577
|
-
const out =
|
|
12578
|
-
mkdirSync(
|
|
12691
|
+
const out = path17.join(outDir, "work", "triage.md");
|
|
12692
|
+
mkdirSync(path17.dirname(out), { recursive: true });
|
|
12579
12693
|
writeFileSync2(out, body, "utf8");
|
|
12580
12694
|
return out;
|
|
12581
12695
|
}
|
|
@@ -12614,11 +12728,11 @@ async function deliveryTriageCommand(args) {
|
|
|
12614
12728
|
}
|
|
12615
12729
|
|
|
12616
12730
|
// src/commands/delivery-execution.ts
|
|
12617
|
-
import { createHash as
|
|
12731
|
+
import { createHash as createHash6, randomBytes as secureRandomBytes } from "crypto";
|
|
12618
12732
|
import { spawn as spawn2 } from "child_process";
|
|
12619
|
-
import { createReadStream, promises as
|
|
12620
|
-
import
|
|
12621
|
-
import { CliError as
|
|
12733
|
+
import { createReadStream, promises as fs15 } from "fs";
|
|
12734
|
+
import path18 from "path";
|
|
12735
|
+
import { CliError as CliError24, CliErrorCode as CliErrorCode22, formatObject as formatObject29 } from "@hcmai/sdk";
|
|
12622
12736
|
init_exit();
|
|
12623
12737
|
var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
|
|
12624
12738
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -12660,11 +12774,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
12660
12774
|
};
|
|
12661
12775
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
12662
12776
|
const plan = { ...core, planId };
|
|
12663
|
-
const plansDir =
|
|
12777
|
+
const plansDir = path18.join(project, ".hcm-delivery", "execution-plans");
|
|
12664
12778
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
12665
|
-
const planFile =
|
|
12779
|
+
const planFile = path18.join(plansDir, `${planId}.json`);
|
|
12666
12780
|
try {
|
|
12667
|
-
await
|
|
12781
|
+
await fs15.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
12668
12782
|
`, {
|
|
12669
12783
|
encoding: "utf8",
|
|
12670
12784
|
mode: 384,
|
|
@@ -12678,7 +12792,7 @@ async function prepareDeliveryExecution(input) {
|
|
|
12678
12792
|
async function executeDeliveryPlan(input) {
|
|
12679
12793
|
if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
|
|
12680
12794
|
const project = await realProject(input.project);
|
|
12681
|
-
const planFile =
|
|
12795
|
+
const planFile = path18.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
12682
12796
|
const plan = await readPlan(project, planFile);
|
|
12683
12797
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
12684
12798
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -12715,13 +12829,13 @@ async function executeDeliveryPlan(input) {
|
|
|
12715
12829
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
12716
12830
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
12717
12831
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
12718
|
-
const receiptFile =
|
|
12832
|
+
const receiptFile = path18.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
12719
12833
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
12720
|
-
const claimsDir =
|
|
12834
|
+
const claimsDir = path18.join(project, ".hcm-delivery", "execution-claims");
|
|
12721
12835
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
12722
|
-
const claimFile =
|
|
12836
|
+
const claimFile = path18.join(claimsDir, `${plan.planId}.json`);
|
|
12723
12837
|
try {
|
|
12724
|
-
await
|
|
12838
|
+
await fs15.writeFile(
|
|
12725
12839
|
claimFile,
|
|
12726
12840
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
12727
12841
|
`,
|
|
@@ -12730,8 +12844,8 @@ async function executeDeliveryPlan(input) {
|
|
|
12730
12844
|
} catch (cause) {
|
|
12731
12845
|
throw invalid2(`\u6267\u884C\u8BA1\u5212\u5DF2\u6D88\u8D39\uFF0C\u62D2\u7EDD\u91CD\u590D\u6267\u884C\uFF1A${plan.planId}`, cause);
|
|
12732
12846
|
}
|
|
12733
|
-
const stdoutHash =
|
|
12734
|
-
const stderrHash =
|
|
12847
|
+
const stdoutHash = createHash6("sha256");
|
|
12848
|
+
const stderrHash = createHash6("sha256");
|
|
12735
12849
|
const run2 = input.runCommand ?? runCurrentCliCommand;
|
|
12736
12850
|
let exitCode;
|
|
12737
12851
|
try {
|
|
@@ -12811,7 +12925,7 @@ function writeDeliveryExecutionReceipt(receipt, format = "json") {
|
|
|
12811
12925
|
process.exitCode = receipt.exitCode;
|
|
12812
12926
|
}
|
|
12813
12927
|
async function readProjectMode(project, environment) {
|
|
12814
|
-
const file =
|
|
12928
|
+
const file = path18.join(project, ".hcm-delivery", "project.yml");
|
|
12815
12929
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
12816
12930
|
let mode;
|
|
12817
12931
|
try {
|
|
@@ -12830,13 +12944,13 @@ async function readProjectMode(project, environment) {
|
|
|
12830
12944
|
return mode;
|
|
12831
12945
|
}
|
|
12832
12946
|
var SKILLS_LOCK_CANDIDATES = [
|
|
12833
|
-
|
|
12834
|
-
|
|
12947
|
+
path18.join("hcm-skills", ".hcm-skills.json"),
|
|
12948
|
+
path18.join(".claude", "skills", ".hcm-skills.json")
|
|
12835
12949
|
];
|
|
12836
12950
|
async function readSkillsLock(project) {
|
|
12837
12951
|
const found = [];
|
|
12838
12952
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
12839
|
-
if (await pathExists(
|
|
12953
|
+
if (await pathExists(path18.join(project, candidate))) found.push(candidate);
|
|
12840
12954
|
}
|
|
12841
12955
|
if (found.length === 0) {
|
|
12842
12956
|
throw invalid2(
|
|
@@ -12848,7 +12962,7 @@ async function readSkillsLock(project) {
|
|
|
12848
12962
|
`\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`
|
|
12849
12963
|
);
|
|
12850
12964
|
}
|
|
12851
|
-
const bytes = await readSafeFile(project,
|
|
12965
|
+
const bytes = await readSafeFile(project, path18.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
12852
12966
|
try {
|
|
12853
12967
|
JSON.parse(bytes.toString("utf8"));
|
|
12854
12968
|
} catch (cause) {
|
|
@@ -12861,7 +12975,7 @@ async function bindDocument(project, reference, label) {
|
|
|
12861
12975
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
12862
12976
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
12863
12977
|
}
|
|
12864
|
-
const file =
|
|
12978
|
+
const file = path18.join(project, relative2);
|
|
12865
12979
|
const bytes = await readSafeFile(project, file, label);
|
|
12866
12980
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
12867
12981
|
}
|
|
@@ -12874,11 +12988,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
12874
12988
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
12875
12989
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
12876
12990
|
}
|
|
12877
|
-
const absolute =
|
|
12991
|
+
const absolute = path18.join(project, relative2);
|
|
12878
12992
|
await assertNoSymlinkComponents(project, relative2);
|
|
12879
|
-
const stat = await
|
|
12993
|
+
const stat = await fs15.stat(absolute).catch(() => null);
|
|
12880
12994
|
if (stat === null) {
|
|
12881
|
-
await
|
|
12995
|
+
await fs15.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
12882
12996
|
throw invalid2(
|
|
12883
12997
|
`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`,
|
|
12884
12998
|
cause
|
|
@@ -13061,7 +13175,7 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
13061
13175
|
const relative2 = safeRelative(reference, label);
|
|
13062
13176
|
let stat;
|
|
13063
13177
|
try {
|
|
13064
|
-
stat = await
|
|
13178
|
+
stat = await fs15.stat(path18.join(project, relative2));
|
|
13065
13179
|
} catch (cause) {
|
|
13066
13180
|
throw invalid2(
|
|
13067
13181
|
`${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`,
|
|
@@ -13072,10 +13186,10 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
13072
13186
|
}
|
|
13073
13187
|
async function bindPayloadDirectory(project, reference, label) {
|
|
13074
13188
|
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
13075
|
-
const root =
|
|
13189
|
+
const root = path18.join(project, relative2);
|
|
13076
13190
|
let stat;
|
|
13077
13191
|
try {
|
|
13078
|
-
stat = await
|
|
13192
|
+
stat = await fs15.stat(root);
|
|
13079
13193
|
} catch {
|
|
13080
13194
|
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
13081
13195
|
}
|
|
@@ -13085,12 +13199,12 @@ async function bindPayloadDirectory(project, reference, label) {
|
|
|
13085
13199
|
const skipToolingAtRoot = relative2 === ".";
|
|
13086
13200
|
const entries = [];
|
|
13087
13201
|
const walk = async (dir, prefix) => {
|
|
13088
|
-
const items = await
|
|
13202
|
+
const items = await fs15.readdir(dir, { withFileTypes: true });
|
|
13089
13203
|
for (const item of [...items].sort(
|
|
13090
13204
|
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
13091
13205
|
)) {
|
|
13092
13206
|
if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
|
|
13093
|
-
const child =
|
|
13207
|
+
const child = path18.join(dir, item.name);
|
|
13094
13208
|
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
13095
13209
|
if (item.isSymbolicLink()) {
|
|
13096
13210
|
throw invalid2(
|
|
@@ -13115,7 +13229,7 @@ ${sha2565(bytes)}`);
|
|
|
13115
13229
|
}
|
|
13116
13230
|
async function bindPayloadFile(project, reference, label) {
|
|
13117
13231
|
const relative2 = safeRelative(reference, label);
|
|
13118
|
-
const file =
|
|
13232
|
+
const file = path18.join(project, relative2);
|
|
13119
13233
|
const bytes = await readSafeFile(project, file, label);
|
|
13120
13234
|
return { path: relative2, kind: "file", sha256: sha2565(bytes) };
|
|
13121
13235
|
}
|
|
@@ -13178,29 +13292,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
13178
13292
|
async function writeReceiptExclusive(target, receipt) {
|
|
13179
13293
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
13180
13294
|
try {
|
|
13181
|
-
await
|
|
13295
|
+
await fs15.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
13182
13296
|
`, {
|
|
13183
13297
|
encoding: "utf8",
|
|
13184
13298
|
mode: 384,
|
|
13185
13299
|
flag: "wx"
|
|
13186
13300
|
});
|
|
13187
|
-
await
|
|
13301
|
+
await fs15.link(temp, target);
|
|
13188
13302
|
} catch (cause) {
|
|
13189
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
13303
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path18.basename(target)}`, cause);
|
|
13190
13304
|
} finally {
|
|
13191
|
-
await
|
|
13305
|
+
await fs15.unlink(temp).catch(() => void 0);
|
|
13192
13306
|
}
|
|
13193
13307
|
}
|
|
13194
13308
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
13195
|
-
await assertNoSymlinkComponents(project,
|
|
13196
|
-
const existing = await
|
|
13309
|
+
await assertNoSymlinkComponents(project, path18.dirname(relative2));
|
|
13310
|
+
const existing = await fs15.lstat(absolute).catch(() => void 0);
|
|
13197
13311
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
13198
13312
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
13199
|
-
if (!existing) await
|
|
13200
|
-
await
|
|
13313
|
+
if (!existing) await fs15.mkdir(absolute, { mode: 448 });
|
|
13314
|
+
await fs15.chmod(absolute, 448);
|
|
13201
13315
|
}
|
|
13202
13316
|
async function pathExists(file) {
|
|
13203
|
-
return
|
|
13317
|
+
return fs15.lstat(file).then(
|
|
13204
13318
|
() => true,
|
|
13205
13319
|
(cause) => {
|
|
13206
13320
|
if (cause.code === "ENOENT") return false;
|
|
@@ -13209,47 +13323,47 @@ async function pathExists(file) {
|
|
|
13209
13323
|
);
|
|
13210
13324
|
}
|
|
13211
13325
|
async function readSafeFile(project, file, label) {
|
|
13212
|
-
const relative2 =
|
|
13213
|
-
if (relative2.startsWith("../") ||
|
|
13326
|
+
const relative2 = path18.relative(project, file).split(path18.sep).join("/");
|
|
13327
|
+
if (relative2.startsWith("../") || path18.isAbsolute(relative2))
|
|
13214
13328
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
13215
13329
|
await assertNoSymlinkComponents(project, relative2);
|
|
13216
13330
|
let stat;
|
|
13217
13331
|
try {
|
|
13218
|
-
stat = await
|
|
13332
|
+
stat = await fs15.lstat(file);
|
|
13219
13333
|
} catch (cause) {
|
|
13220
13334
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
13221
13335
|
}
|
|
13222
13336
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
13223
13337
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
13224
|
-
return
|
|
13338
|
+
return fs15.readFile(file);
|
|
13225
13339
|
}
|
|
13226
13340
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
13227
13341
|
const parts = relative2.split("/").filter(Boolean);
|
|
13228
13342
|
let current = project;
|
|
13229
13343
|
for (const part of parts) {
|
|
13230
|
-
current =
|
|
13231
|
-
const stat = await
|
|
13344
|
+
current = path18.join(current, part);
|
|
13345
|
+
const stat = await fs15.lstat(current).catch(() => void 0);
|
|
13232
13346
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
13233
13347
|
if (!stat) break;
|
|
13234
13348
|
}
|
|
13235
13349
|
}
|
|
13236
13350
|
async function realProject(requested) {
|
|
13237
|
-
const absolute =
|
|
13351
|
+
const absolute = path18.resolve(requested);
|
|
13238
13352
|
let project;
|
|
13239
13353
|
try {
|
|
13240
|
-
project = await
|
|
13354
|
+
project = await fs15.realpath(absolute);
|
|
13241
13355
|
} catch (cause) {
|
|
13242
13356
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
13243
13357
|
}
|
|
13244
|
-
const stat = await
|
|
13358
|
+
const stat = await fs15.stat(project);
|
|
13245
13359
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
13246
13360
|
return project;
|
|
13247
13361
|
}
|
|
13248
13362
|
function safeRelative(reference, label) {
|
|
13249
|
-
if (!reference ||
|
|
13363
|
+
if (!reference || path18.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
13250
13364
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
13251
13365
|
}
|
|
13252
|
-
const normalized =
|
|
13366
|
+
const normalized = path18.normalize(reference).split(path18.sep).join("/");
|
|
13253
13367
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
13254
13368
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
13255
13369
|
}
|
|
@@ -13289,10 +13403,10 @@ function canonicalJson(value) {
|
|
|
13289
13403
|
return JSON.stringify(value) ?? "null";
|
|
13290
13404
|
}
|
|
13291
13405
|
function sha2565(value) {
|
|
13292
|
-
return
|
|
13406
|
+
return createHash6("sha256").update(value).digest("hex");
|
|
13293
13407
|
}
|
|
13294
13408
|
async function sha256File(file) {
|
|
13295
|
-
const hash =
|
|
13409
|
+
const hash = createHash6("sha256");
|
|
13296
13410
|
await new Promise((resolve4, reject) => {
|
|
13297
13411
|
const stream = createReadStream(file);
|
|
13298
13412
|
stream.on("data", (chunk) => hash.update(chunk));
|
|
@@ -13302,7 +13416,7 @@ async function sha256File(file) {
|
|
|
13302
13416
|
return hash.digest("hex");
|
|
13303
13417
|
}
|
|
13304
13418
|
function invalid2(message, cause) {
|
|
13305
|
-
return new
|
|
13419
|
+
return new CliError24({ code: CliErrorCode22.INVALID_ARGUMENT, message, cause });
|
|
13306
13420
|
}
|
|
13307
13421
|
function nextCommandHint(planId, project, argv) {
|
|
13308
13422
|
const quoted = argv.map((a) => /[\s"'$`\\]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a);
|
|
@@ -13318,21 +13432,21 @@ import {
|
|
|
13318
13432
|
adminResetPassword,
|
|
13319
13433
|
formatObject as formatObject30,
|
|
13320
13434
|
fromAxiosError as fromAxiosError22,
|
|
13321
|
-
CliError as
|
|
13322
|
-
CliErrorCode as
|
|
13435
|
+
CliError as CliError25,
|
|
13436
|
+
CliErrorCode as CliErrorCode23
|
|
13323
13437
|
} from "@hcmai/sdk";
|
|
13324
13438
|
function buildAdminResetPasswordRequest(args, password) {
|
|
13325
13439
|
const hasId = Boolean(args.id);
|
|
13326
13440
|
const hasUsername = Boolean(args.username);
|
|
13327
13441
|
if (hasId === hasUsername) {
|
|
13328
|
-
throw new
|
|
13329
|
-
code:
|
|
13442
|
+
throw new CliError25({
|
|
13443
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
13330
13444
|
message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
|
|
13331
13445
|
});
|
|
13332
13446
|
}
|
|
13333
13447
|
if (!password) {
|
|
13334
|
-
throw new
|
|
13335
|
-
code:
|
|
13448
|
+
throw new CliError25({
|
|
13449
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
13336
13450
|
message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
|
|
13337
13451
|
});
|
|
13338
13452
|
}
|
|
@@ -13361,8 +13475,8 @@ async function promptPasswordTwice() {
|
|
|
13361
13475
|
const password = await promptSecret("\u65B0\u5BC6\u7801: ");
|
|
13362
13476
|
const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
|
|
13363
13477
|
if (password !== confirmation) {
|
|
13364
|
-
throw new
|
|
13365
|
-
code:
|
|
13478
|
+
throw new CliError25({
|
|
13479
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
13366
13480
|
message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
|
|
13367
13481
|
});
|
|
13368
13482
|
}
|
|
@@ -13577,7 +13691,10 @@ program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6
|
|
|
13577
13691
|
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(
|
|
13578
13692
|
"--scope <scope>",
|
|
13579
13693
|
"\u5F3A\u5236 Action scope\uFF1Aclass | object\uFF08\u9ED8\u8BA4\uFF1A\u6709 --id \u4E3A object\uFF0C\u5426\u5219 class\uFF09"
|
|
13580
|
-
).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").
|
|
13694
|
+
).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").option(
|
|
13695
|
+
"--artifact-output <path>",
|
|
13696
|
+
"\u628A\u6807\u51C6\u53EA\u8BFB\u5236\u54C1\uFF08Core ActionArtifact\uFF09\u843D\u5230\u8FD9\u4E2A**\u6587\u4EF6**\u8DEF\u5F84\uFF1B\u53EA\u8BA4\u516C\u5171\u5951\u7EA6\u4FE1\u5C01\uFF0C\u4E0D\u731C\u5B57\u6BB5\uFF0C\u4E5F\u4E0D\u6539\u53D8\u98CE\u9669\u5224\u6863"
|
|
13697
|
+
).option("--artifact-force", "\u76EE\u6807\u5DF2\u5B58\u5728\u65F6\u624D\u9700\u8981\u5B83\u2014\u2014\u9ED8\u8BA4\u62D2\u7EDD\u8986\u76D6\uFF0C\u514D\u5F97\u628A\u4E0A\u4E00\u8F6E\u7684\u8BC1\u636E\u6084\u6084\u6362\u6389").action((spec, opts) => actionCommand(spec, opts));
|
|
13581
13698
|
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(
|
|
13582
13699
|
"--i18n",
|
|
13583
13700
|
"\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"
|
|
@@ -13687,7 +13804,7 @@ program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u
|
|
|
13687
13804
|
).action((model, opts) => updateCommand(model, opts));
|
|
13688
13805
|
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));
|
|
13689
13806
|
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));
|
|
13690
|
-
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((
|
|
13807
|
+
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((path19, opts) => openCommand(path19, opts));
|
|
13691
13808
|
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");
|
|
13692
13809
|
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));
|
|
13693
13810
|
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(
|