@hcmai/cli 0.4.26 → 0.4.27
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 +100 -13
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8548,6 +8548,28 @@ function classify(argv, actionResolution) {
|
|
|
8548
8548
|
if (name === "delivery" && subcommand === "assess") {
|
|
8549
8549
|
return direct("R0", "local-discovery", "risk-assessment");
|
|
8550
8550
|
}
|
|
8551
|
+
if (name === "models") return direct("R0", "product-discovery", "model-discovery");
|
|
8552
|
+
if (name === "config") {
|
|
8553
|
+
if (["list", "show", "get"].includes(subcommand)) return direct("R0", "local-discovery", "config-read");
|
|
8554
|
+
return forbidden("identity-governance", "\u4FEE\u6539\u672C\u673A\u5168\u5C40\u914D\u7F6E\u4F1A\u6539\u53D8\u540E\u7EED\u6240\u6709\u547D\u4EE4\u7684\u73AF\u5883\u4E0E\u8EAB\u4EFD\uFF0C\u5C5E\u6CBB\u7406\u64CD\u4F5C\u3002");
|
|
8555
|
+
}
|
|
8556
|
+
if (name === "upgrade" || name === "self-update") {
|
|
8557
|
+
return direct("R1", "managed-local-write", "cli-self-upgrade");
|
|
8558
|
+
}
|
|
8559
|
+
if (name === "datapackage") {
|
|
8560
|
+
if (subcommand === "pack") return direct("R1", "local-validation", "datapackage-pack");
|
|
8561
|
+
if (subcommand === "status") return direct("R1", "remote-read", "datapackage-status");
|
|
8562
|
+
if (subcommand === "install") return guarded("tenant-data-write", "datapackage-install");
|
|
8563
|
+
return forbidden("unknown-command", "\u672A\u77E5 datapackage \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
|
|
8564
|
+
}
|
|
8565
|
+
if (name === "mini") {
|
|
8566
|
+
return forbidden("removed-command", "`hcm mini` \u5DF2\u79FB\u9664\uFF0C\u6539\u7528 `hcm workspace`\u3002");
|
|
8567
|
+
}
|
|
8568
|
+
if (name === "chiron") {
|
|
8569
|
+
if (subcommand === "doctor") return direct("R0", "local-discovery", "chiron-doctor");
|
|
8570
|
+
if (subcommand === "init") return direct("R1", "managed-local-write", "chiron-project-scaffold");
|
|
8571
|
+
return forbidden("unknown-command", "\u672A\u77E5 chiron \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
|
|
8572
|
+
}
|
|
8551
8573
|
if (name === "skills") {
|
|
8552
8574
|
if (subcommand === "list" || subcommand === "show") {
|
|
8553
8575
|
return direct("R0", "product-discovery", "skill-discovery");
|
|
@@ -9931,17 +9953,17 @@ import {
|
|
|
9931
9953
|
formatObject as formatObject24,
|
|
9932
9954
|
httpProbe as httpProbe2,
|
|
9933
9955
|
isTempEnv as isTempEnv3,
|
|
9934
|
-
listIdentities as
|
|
9956
|
+
listIdentities as listIdentities5,
|
|
9935
9957
|
loadEnv as loadEnv11,
|
|
9936
|
-
loadGlobalConfig as
|
|
9958
|
+
loadGlobalConfig as loadGlobalConfig11
|
|
9937
9959
|
} from "@hcmai/sdk";
|
|
9938
9960
|
|
|
9939
9961
|
// src/commands/chiron-project.ts
|
|
9940
9962
|
import { promises as fs9 } from "fs";
|
|
9941
9963
|
import os4 from "os";
|
|
9942
9964
|
import path9 from "path";
|
|
9943
|
-
import { spawnSync } from "child_process";
|
|
9944
|
-
import { hcmConfigDir, listEnvs as listEnvs3, loadEnv as loadEnv10 } from "@hcmai/sdk";
|
|
9965
|
+
import { execFileSync, spawnSync } from "child_process";
|
|
9966
|
+
import { hcmConfigDir, listEnvs as listEnvs3, listIdentities as listIdentities4, loadEnv as loadEnv10, loadGlobalConfig as loadGlobalConfig10 } from "@hcmai/sdk";
|
|
9945
9967
|
var ENV_FILE = "env.yaml";
|
|
9946
9968
|
var SKILLS_DIR = "hcm-skills";
|
|
9947
9969
|
var CASES_REPO_URL = "https://cnb.cool/hcm/chiron-cases.git";
|
|
@@ -10003,13 +10025,19 @@ function projectEnvFromConfig(cfg) {
|
|
|
10003
10025
|
tenant: cfg.tenantId ?? "1"
|
|
10004
10026
|
};
|
|
10005
10027
|
}
|
|
10006
|
-
async function findEnvByEndpoint(endpoint) {
|
|
10028
|
+
async function findEnvByEndpoint(endpoint, tenant2) {
|
|
10007
10029
|
const wanted = normalizeOrigin(endpoint);
|
|
10030
|
+
const matches = [];
|
|
10008
10031
|
for (const name of await listEnvs3().catch(() => [])) {
|
|
10009
10032
|
const config2 = await loadEnv10(name).catch(() => null);
|
|
10010
|
-
if (config2
|
|
10033
|
+
if (!config2 || normalizeOrigin(config2.endpoint) !== wanted) continue;
|
|
10034
|
+
matches.push({ name, config: config2, hasIdentity: (await listIdentities4(name).catch(() => [])).length > 0 });
|
|
10011
10035
|
}
|
|
10012
|
-
return null;
|
|
10036
|
+
if (matches.length === 0) return null;
|
|
10037
|
+
const active = (await loadGlobalConfig10().catch(() => null))?.activeEnv;
|
|
10038
|
+
const usable = matches.filter((m) => m.hasIdentity);
|
|
10039
|
+
const pick = usable.find((m) => m.name === active) ?? (tenant2 ? usable.find((m) => (m.config.tenantId ?? "1") === tenant2) : void 0) ?? usable[0] ?? matches.find((m) => m.name === active) ?? matches[0];
|
|
10040
|
+
return { name: pick.name, config: pick.config };
|
|
10013
10041
|
}
|
|
10014
10042
|
function renderChironAgentInstructions() {
|
|
10015
10043
|
return [
|
|
@@ -10154,6 +10182,60 @@ function firstLine(stderr, error) {
|
|
|
10154
10182
|
const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
|
|
10155
10183
|
return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
|
|
10156
10184
|
}
|
|
10185
|
+
var JIRA_BASE = (process.env.JIRA_BASE || "https://jira.hcmcloud.cn").replace(/\/+$/, "");
|
|
10186
|
+
var JIRA_PROJECT = process.env.JIRA_PROJECT || "HCMNX";
|
|
10187
|
+
var JIRA_TOKEN_FILE = () => path9.join(os4.homedir(), ".config", "hcm", "jira-token");
|
|
10188
|
+
var JIRA_KEYCHAIN = "jira-hcmcloud";
|
|
10189
|
+
async function jiraTokenSource() {
|
|
10190
|
+
if (process.env.JIRA_TOKEN?.trim()) return { token: process.env.JIRA_TOKEN.trim(), from: "\u73AF\u5883\u53D8\u91CF JIRA_TOKEN" };
|
|
10191
|
+
const file = process.env.JIRA_TOKEN_FILE || JIRA_TOKEN_FILE();
|
|
10192
|
+
try {
|
|
10193
|
+
const value = (await fs9.readFile(file, "utf8")).trim();
|
|
10194
|
+
if (value) return { token: value, from: file };
|
|
10195
|
+
} catch {
|
|
10196
|
+
}
|
|
10197
|
+
try {
|
|
10198
|
+
const out = execFileSync("security", ["find-generic-password", "-s", JIRA_KEYCHAIN, "-w"], {
|
|
10199
|
+
encoding: "utf8",
|
|
10200
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
10201
|
+
}).trim();
|
|
10202
|
+
if (out) return { token: out, from: `\u94A5\u5319\u4E32 ${JIRA_KEYCHAIN}` };
|
|
10203
|
+
} catch {
|
|
10204
|
+
}
|
|
10205
|
+
return null;
|
|
10206
|
+
}
|
|
10207
|
+
async function inspectJira() {
|
|
10208
|
+
const src = await jiraTokenSource();
|
|
10209
|
+
if (!src) {
|
|
10210
|
+
return {
|
|
10211
|
+
ok: false,
|
|
10212
|
+
reason: `\u6CA1\u6709\u4EE4\u724C\u3002\u5728 ${JIRA_BASE} \u53F3\u4E0A\u89D2\u5934\u50CF \u2192 \u4E2A\u4EBA\u8BBE\u7F6E \u2192 Personal Access Tokens \u5EFA\u4E00\u4E2A\uFF0C\u7136\u540E\uFF1Amkdir -p ~/.config/hcm && read -rs pat && printf "%s" "$pat" > ~/.config/hcm/jira-token && chmod 600 ~/.config/hcm/jira-token && unset pat`
|
|
10213
|
+
};
|
|
10214
|
+
}
|
|
10215
|
+
const call = async (path_) => {
|
|
10216
|
+
const res = await fetch(`${JIRA_BASE}${path_}`, {
|
|
10217
|
+
headers: { Authorization: `Bearer ${src.token}`, Accept: "application/json" },
|
|
10218
|
+
signal: AbortSignal.timeout(15e3)
|
|
10219
|
+
});
|
|
10220
|
+
return res;
|
|
10221
|
+
};
|
|
10222
|
+
try {
|
|
10223
|
+
const me = await call("/rest/api/2/myself");
|
|
10224
|
+
if (me.status === 401) return { ok: false, from: src.from, reason: "\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F\uFF0C\u91CD\u5EFA PAT \u540E\u91CD\u65B0\u5B58\u4E00\u6B21" };
|
|
10225
|
+
if (!me.ok) return { ok: false, from: src.from, reason: `\u8FDE\u5F97\u4E0A\u4F46 /myself \u8FD4\u56DE ${me.status}` };
|
|
10226
|
+
const who = (await me.json()).displayName ?? "";
|
|
10227
|
+
const project = await call(`/rest/api/2/project/${JIRA_PROJECT}`);
|
|
10228
|
+
return {
|
|
10229
|
+
ok: project.ok,
|
|
10230
|
+
from: src.from,
|
|
10231
|
+
who,
|
|
10232
|
+
projectVisible: project.ok,
|
|
10233
|
+
reason: project.ok ? void 0 : `\u770B\u4E0D\u5230\u9879\u76EE ${JIRA_PROJECT}\uFF08${project.status}\uFF09\uFF0C\u627E Jira \u7BA1\u7406\u5458\u5F00\u6743\u9650`
|
|
10234
|
+
};
|
|
10235
|
+
} catch (e) {
|
|
10236
|
+
return { ok: false, from: src.from, reason: `\u8FDE\u4E0D\u4E0A ${JIRA_BASE}\uFF1A${e.message}` };
|
|
10237
|
+
}
|
|
10238
|
+
}
|
|
10157
10239
|
async function exists2(file) {
|
|
10158
10240
|
try {
|
|
10159
10241
|
await fs9.access(file);
|
|
@@ -10193,7 +10275,7 @@ var defaultChironInitDeps = {
|
|
|
10193
10275
|
caseLibrary: (envName) => ensureCaseLibrary(envName)
|
|
10194
10276
|
};
|
|
10195
10277
|
async function resolveLoggedInEnv() {
|
|
10196
|
-
const g = await
|
|
10278
|
+
const g = await loadGlobalConfig11();
|
|
10197
10279
|
const name = g.activeEnv;
|
|
10198
10280
|
const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
|
|
10199
10281
|
if (!name) {
|
|
@@ -10209,7 +10291,7 @@ async function resolveLoggedInEnv() {
|
|
|
10209
10291
|
message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10210
10292
|
});
|
|
10211
10293
|
}
|
|
10212
|
-
const identities = await
|
|
10294
|
+
const identities = await listIdentities5(name).catch(() => []);
|
|
10213
10295
|
if (identities.length === 0) {
|
|
10214
10296
|
throw new CliError21({
|
|
10215
10297
|
code: CliErrorCode20.IDENTITY_NOT_FOUND,
|
|
@@ -10360,7 +10442,8 @@ var defaultDeps = {
|
|
|
10360
10442
|
fixCases: async (envName) => {
|
|
10361
10443
|
await ensureCaseLibrary(envName);
|
|
10362
10444
|
},
|
|
10363
|
-
inspectCases: () => inspectCaseLibrary()
|
|
10445
|
+
inspectCases: () => inspectCaseLibrary(),
|
|
10446
|
+
inspectJira: () => inspectJira()
|
|
10364
10447
|
};
|
|
10365
10448
|
async function runChironDoctor(args, deps = defaultDeps) {
|
|
10366
10449
|
const root = path11.resolve(args.project ?? ".");
|
|
@@ -10383,7 +10466,7 @@ async function runChironDoctor(args, deps = defaultDeps) {
|
|
|
10383
10466
|
return finish(report);
|
|
10384
10467
|
}
|
|
10385
10468
|
report.env = env2;
|
|
10386
|
-
const found = await findEnvByEndpoint(env2.endpoint);
|
|
10469
|
+
const found = await findEnvByEndpoint(env2.endpoint, env2.tenant);
|
|
10387
10470
|
const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
|
|
10388
10471
|
if (!found) {
|
|
10389
10472
|
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
|
|
@@ -10444,6 +10527,10 @@ async function runChironDoctor(args, deps = defaultDeps) {
|
|
|
10444
10527
|
cases = await casesLine();
|
|
10445
10528
|
}
|
|
10446
10529
|
report.lines.push(cases);
|
|
10530
|
+
const jira = await deps.inspectJira();
|
|
10531
|
+
report.lines.push(
|
|
10532
|
+
jira.ok ? { item: "Jira", verdict: "ok", detail: `${jira.who || "\u5DF2\u8FDE\u63A5"} \xB7 \u770B\u5F97\u5230 ${JIRA_PROJECT}\uFF08\u4EE4\u724C\u6765\u81EA ${jira.from}\uFF09` } : { item: "Jira", verdict: "warn", detail: jira.reason ?? "\u4E0D\u53EF\u7528", nextStep: "\u73B0\u5728\u4E0D\u914D\u4E5F\u80FD\u4EA4\u4ED8\uFF1B\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u8981\u63D0\u5355\u65F6\u5FC5\u987B\u5148\u914D\u597D" }
|
|
10533
|
+
);
|
|
10447
10534
|
return finish(report);
|
|
10448
10535
|
}
|
|
10449
10536
|
function finish(report) {
|
|
@@ -12219,9 +12306,9 @@ identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 e
|
|
|
12219
12306
|
identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
|
|
12220
12307
|
var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
|
|
12221
12308
|
user.command("reset-password").description("\u7531 admin.system \u5B89\u5168\u91CD\u7F6E\u7528\u6237\u5BC6\u7801\uFF0C\u5E76\u4F7F\u65E2\u6709\u4F1A\u8BDD\u5931\u6548").option("--id <uuid>", "\u76EE\u6807\u7528\u6237 ID\uFF08\u4E0E --username \u4E8C\u9009\u4E00\uFF09").option("--username <user>", "\u76EE\u6807\u7528\u6237\u540D\uFF08\u4E0E --id \u4E8C\u9009\u4E00\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u65B0\u5BC6\u7801\uFF08Agent/\u53D7\u63A7\u4EA4\u4ED8\u5FC5\u987B\u4F7F\u7528\uFF09").option("--no-force-change", "\u4E0B\u6B21\u767B\u5F55\u4E0D\u5F3A\u5236\u6539\u5BC6\uFF08\u4EC5\u9650\u5DF2\u6279\u51C6\u7684\u9694\u79BB\u6D4B\u8BD5\u73AF\u5883\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u5FC5\u987B\u5177\u5907 admin.system\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => userResetPasswordCommand(opts));
|
|
12222
|
-
var chiron = program.command("chiron").description("\u777F\u620E\u987E\u95EE\u9879\u76EE\uFF1Ainit \u4E00\u6761\u547D\u4EE4\u521D\u59CB\u5316\u9879\u76EE\u4ED3\uFF0Cdoctor \
|
|
12309
|
+
var chiron = program.command("chiron").description("\u777F\u620E\u987E\u95EE\u9879\u76EE\uFF1Ainit \u4E00\u6761\u547D\u4EE4\u521D\u59CB\u5316\u9879\u76EE\u4ED3\uFF0Cdoctor \u56DB\u884C\u6838\u5BF9\u80FD\u4E0D\u80FD\u5F00\u5DE5");
|
|
12223
12310
|
chiron.command("init").description("\u521D\u59CB\u5316\u987E\u95EE\u9879\u76EE\u4ED3\uFF1A\u5199 env.yaml\uFF08\u7528\u521A hcm login \u7684\u73AF\u5883\uFF09\u3001\u5EFA\u76EE\u5F55\u3001\u88C5\u5168\u90E8\u6280\u80FD\u3001\u63A5\u6848\u4F8B\u5E93\uFF1B\u91CD\u8DD1\u5B89\u5168").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--skip-skills", "\u4E0D\u88C5\u6280\u80FD\uFF08\u79BB\u7EBF/\u6D4B\u8BD5\uFF09").option("--skip-cases", "\u4E0D\u63A5\u6848\u4F8B\u5E93").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironInitCommand(opts));
|
|
12224
|
-
chiron.command("doctor").description("\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u63A5\u6CA1\u63A5").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--fix", "\u80FD\u81EA\u52A8\u8865\u7684\u8865\u4E0A\uFF08\u6280\u80FD / \u6848\u4F8B\u5E93\uFF09\u540E\u518D\u6838\u4E00\u904D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
|
|
12311
|
+
chiron.command("doctor").description("\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u63A5\u6CA1\u63A5 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--fix", "\u80FD\u81EA\u52A8\u8865\u7684\u8865\u4E0A\uFF08\u6280\u80FD / \u6848\u4F8B\u5E93\uFF09\u540E\u518D\u6838\u4E00\u904D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
|
|
12225
12312
|
var delivery = program.command("delivery").description("\u987E\u95EE\u4EA4\u4ED8\uFF1A\u73B0\u573A\u63A2\u6D3B\u3001\u98CE\u9669\u8BC4\u4F30\u4E0E\u4E00\u6B21\u6027\u53D7\u63A7\u6267\u884C\u5408\u540C");
|
|
12226
12313
|
delivery.command("assess").description("\u8BC4\u4F30\u4E00\u6B21 HCM CLI argv\uFF1BAction \u98CE\u63A7\u58F0\u660E\u8BFB\u53D6\u81EA\u76EE\u6807 Core\uFF0C\u7528 -- \u5206\u9694\u88AB\u8BC4\u4F30\u547D\u4EE4").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u8BC4\u4F30\u7684 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryAssessCommand(command, opts));
|
|
12227
12314
|
delivery.command("doctor").description("\u56DB\u6761\u951A\u70B9\u63A2\u6D3B\uFF1A\u8FDE\u901A / \u6211\u662F\u8C01 / configAdmin / \u7AD9\u5728\u54EA\u4E00\u5C42").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--capabilities <s>", "\u722C\u53D6\u65F6\u58F0\u660E\u7684 capability \u4E32\uFF08\u4F1A\u968F\u56DB\u5143\u7EC4\u7559\u6863\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryDoctorCommand(opts));
|