@hcmai/cli 0.15.8 → 0.15.10
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 +671 -333
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +61 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -864,7 +864,11 @@ var StreamPresenter_exports = {};
|
|
|
864
864
|
__export(StreamPresenter_exports, {
|
|
865
865
|
StreamPresenter: () => StreamPresenter
|
|
866
866
|
});
|
|
867
|
-
import {
|
|
867
|
+
import {
|
|
868
|
+
CliErrorCode as CliErrorCode16,
|
|
869
|
+
createV4Reducer,
|
|
870
|
+
truncateDisplay
|
|
871
|
+
} from "@hcmai/sdk";
|
|
868
872
|
var debug, StreamPresenter;
|
|
869
873
|
var init_StreamPresenter = __esm({
|
|
870
874
|
"src/streaming/StreamPresenter.ts"() {
|
|
@@ -1014,7 +1018,7 @@ var init_StreamPresenter = __esm({
|
|
|
1014
1018
|
process.stdout.write(JSON.stringify(ev) + "\n");
|
|
1015
1019
|
if (ev.type === "response.completed") return this.result("completed");
|
|
1016
1020
|
if (ev.type === "response.interrupted") return this.result("interrupted");
|
|
1017
|
-
if (ev.type === "response.failed") throw this.toError(ev);
|
|
1021
|
+
if (ev.type === "response.failed") throw await this.toError(ev);
|
|
1018
1022
|
if (ev.type === "message.stop" && !ev.payload?.parentToolUseId) {
|
|
1019
1023
|
this.sawRootStop = true;
|
|
1020
1024
|
}
|
|
@@ -1028,7 +1032,7 @@ var init_StreamPresenter = __esm({
|
|
|
1028
1032
|
}
|
|
1029
1033
|
if (ev.type === "response.failed") {
|
|
1030
1034
|
this.renderer.stopSpinner();
|
|
1031
|
-
throw this.toError(ev);
|
|
1035
|
+
throw await this.toError(ev);
|
|
1032
1036
|
}
|
|
1033
1037
|
if (ev.type === "response.interrupted") {
|
|
1034
1038
|
this.renderer.showInterrupted(ev.payload?.reason ?? "UNKNOWN");
|
|
@@ -1037,7 +1041,7 @@ var init_StreamPresenter = __esm({
|
|
|
1037
1041
|
if (ev.type === "message.stop" && !ev.payload?.parentToolUseId) {
|
|
1038
1042
|
this.reducer.handle(ev.type, ev.payload ?? {});
|
|
1039
1043
|
const reason = ev.payload?.stopReason;
|
|
1040
|
-
if (reason === "error") throw this.toError(ev);
|
|
1044
|
+
if (reason === "error") throw await this.toError(ev);
|
|
1041
1045
|
if (reason === "interrupted") {
|
|
1042
1046
|
this.renderer.showInterrupted("INTERRUPTED");
|
|
1043
1047
|
return this.result("interrupted");
|
|
@@ -1086,9 +1090,12 @@ var init_StreamPresenter = __esm({
|
|
|
1086
1090
|
return { status, traceId: this.traceId, streamId: this.streamId };
|
|
1087
1091
|
}
|
|
1088
1092
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1089
|
-
toError(ev) {
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1093
|
+
async toError(ev) {
|
|
1094
|
+
const fromConn = await this.opts.serverError?.() ?? null;
|
|
1095
|
+
const code = ev.payload?.errorCode ?? ev.payload?.code ?? fromConn?.code;
|
|
1096
|
+
const message = ev.payload?.message ?? fromConn?.message;
|
|
1097
|
+
const err = new Error(message ?? "stream failed");
|
|
1098
|
+
err.code = code ?? CliErrorCode16.STREAM_FAILED_NO_SERVER_CODE;
|
|
1092
1099
|
err.traceId = ev.traceId;
|
|
1093
1100
|
return err;
|
|
1094
1101
|
}
|
|
@@ -2095,12 +2102,6 @@ async function runInkRepl(args) {
|
|
|
2095
2102
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
2096
2103
|
assertDangerWrite(ctx.environmentSafety, "\u542F\u52A8\u4EA4\u4E92\u4F1A\u8BDD\uFF08\u53EF\u80FD\u6267\u884C\u4E1A\u52A1\u5199\u5165\uFF09");
|
|
2097
2104
|
const client3 = HcmClient10.fromAuthContext(ctx);
|
|
2098
|
-
const ws = new WsClient({
|
|
2099
|
-
endpoint: conversationWebSocketEndpoint(ctx.endpoint),
|
|
2100
|
-
getAccessToken: () => client3.getAccessToken(),
|
|
2101
|
-
onTokenExpiring: () => client3.handleRefresh()
|
|
2102
|
-
});
|
|
2103
|
-
await ws.connect();
|
|
2104
2105
|
let initialConversationId;
|
|
2105
2106
|
if (args.resume && args.conversation) {
|
|
2106
2107
|
throw new Error("--resume \u548C --conversation \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\uFF1B\u65B0\u547D\u4EE4\u8BF7\u7528 --resume <conversationId>");
|
|
@@ -2113,6 +2114,13 @@ async function runInkRepl(args) {
|
|
|
2113
2114
|
} else if (args.conversation && args.conversation !== "NEW") {
|
|
2114
2115
|
initialConversationId = args.conversation;
|
|
2115
2116
|
}
|
|
2117
|
+
const ws = new WsClient({
|
|
2118
|
+
endpoint: conversationWebSocketEndpoint(ctx.endpoint),
|
|
2119
|
+
getAccessToken: () => client3.getAccessToken(),
|
|
2120
|
+
onTokenExpiring: () => client3.handleRefresh(),
|
|
2121
|
+
conversationId: initialConversationId
|
|
2122
|
+
});
|
|
2123
|
+
await ws.connect();
|
|
2116
2124
|
const { waitUntilExit } = render(
|
|
2117
2125
|
React3.createElement(ReplApp, {
|
|
2118
2126
|
ws,
|
|
@@ -3842,15 +3850,7 @@ import {
|
|
|
3842
3850
|
} from "@hcmai/sdk";
|
|
3843
3851
|
async function queryCommand(model, args) {
|
|
3844
3852
|
try {
|
|
3845
|
-
const dsl =
|
|
3846
|
-
if (args.filter) dsl.filter = parseJsonOrThrow(args.filter, "--filter");
|
|
3847
|
-
if (args.sort) dsl.sort = parseJsonOrThrow(args.sort, "--sort");
|
|
3848
|
-
if (args.additions) dsl.additions = parseAdditionsOrThrow(args.additions);
|
|
3849
|
-
if (args.fields) dsl.fields = args.fields.split(",").map((s) => s.trim());
|
|
3850
|
-
if (args.keyword) dsl.keyword = args.keyword;
|
|
3851
|
-
if (args.limit) dsl.limit = Number(args.limit);
|
|
3852
|
-
if (args.offset) dsl.offset = Number(args.offset);
|
|
3853
|
-
if (!dsl.limit) dsl.limit = 20;
|
|
3853
|
+
const dsl = buildQueryDsl(args);
|
|
3854
3854
|
const client3 = HcmClient2.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
3855
3855
|
const result = await client3.query(model, dsl);
|
|
3856
3856
|
const fmt = args.output ?? "table";
|
|
@@ -3863,6 +3863,19 @@ async function queryCommand(model, args) {
|
|
|
3863
3863
|
exitWithError(e);
|
|
3864
3864
|
}
|
|
3865
3865
|
}
|
|
3866
|
+
function buildQueryDsl(args) {
|
|
3867
|
+
const dsl = {};
|
|
3868
|
+
if (args.plugin) dsl.plugin = args.plugin;
|
|
3869
|
+
if (args.filter) dsl.filter = parseJsonOrThrow(args.filter, "--filter");
|
|
3870
|
+
if (args.sort) dsl.sort = parseJsonOrThrow(args.sort, "--sort");
|
|
3871
|
+
if (args.additions) dsl.additions = parseAdditionsOrThrow(args.additions);
|
|
3872
|
+
if (args.fields) dsl.fields = args.fields.split(",").map((s) => s.trim());
|
|
3873
|
+
if (args.keyword) dsl.keyword = args.keyword;
|
|
3874
|
+
if (args.limit) dsl.limit = Number(args.limit);
|
|
3875
|
+
if (args.offset) dsl.offset = Number(args.offset);
|
|
3876
|
+
if (!dsl.limit) dsl.limit = 20;
|
|
3877
|
+
return dsl;
|
|
3878
|
+
}
|
|
3866
3879
|
function printQueryResult(result, fmt) {
|
|
3867
3880
|
const out = formatRows(result.rows, { format: fmt });
|
|
3868
3881
|
process.stdout.write(out + "\n");
|
|
@@ -4565,6 +4578,15 @@ async function describeCommand(model, args) {
|
|
|
4565
4578
|
exitWithError(e);
|
|
4566
4579
|
}
|
|
4567
4580
|
}
|
|
4581
|
+
function formatEnumValues(enums) {
|
|
4582
|
+
if (!enums?.length) return "";
|
|
4583
|
+
const items = enums.map((e) => {
|
|
4584
|
+
const raw = e.value ?? e.key;
|
|
4585
|
+
const shown = raw === void 0 || raw === null ? "?" : String(raw);
|
|
4586
|
+
return e.label && e.label !== shown ? `${shown}=${e.label}` : shown;
|
|
4587
|
+
});
|
|
4588
|
+
return `[${items.join("|")}]`;
|
|
4589
|
+
}
|
|
4568
4590
|
function formatDescriptionTable(desc, verbose = false) {
|
|
4569
4591
|
const lines = [`=== ${desc.model} ===`];
|
|
4570
4592
|
if (desc.labels.zh_CN) lines.push(`zh_CN: ${desc.labels.zh_CN}`);
|
|
@@ -4572,7 +4594,8 @@ function formatDescriptionTable(desc, verbose = false) {
|
|
|
4572
4594
|
lines.push(`fields (${desc.fields.length}):`);
|
|
4573
4595
|
for (const f of desc.fields) {
|
|
4574
4596
|
const req = f.required ? " required" : " ";
|
|
4575
|
-
const
|
|
4597
|
+
const extras = verbose ? [f.label, f.description, formatEnumValues(f.enums)] : [f.label];
|
|
4598
|
+
const lbl = extras.filter((s) => s && s.length > 0).map((s) => ` ${s}`).join("");
|
|
4576
4599
|
const type = f.i18n ? `${f.type} (i18n)` : f.type;
|
|
4577
4600
|
const objectRef = f.object ? ` \u2192 ${f.object}` : "";
|
|
4578
4601
|
lines.push(` ${f.name.padEnd(20)} ${type.padEnd(14)} ${req}${lbl}${objectRef}`);
|
|
@@ -4609,9 +4632,6 @@ function formatDescriptionTable(desc, verbose = false) {
|
|
|
4609
4632
|
}
|
|
4610
4633
|
|
|
4611
4634
|
// src/commands/chat.ts
|
|
4612
|
-
init_exit();
|
|
4613
|
-
init_impersonation_lifecycle();
|
|
4614
|
-
init_auth_guard();
|
|
4615
4635
|
import {
|
|
4616
4636
|
HcmClient as HcmClient11,
|
|
4617
4637
|
WsClient as WsClient2,
|
|
@@ -4630,7 +4650,7 @@ import {
|
|
|
4630
4650
|
findLastAssistantTarget,
|
|
4631
4651
|
SUPERSEDED_STATUS,
|
|
4632
4652
|
CliError as CliError16,
|
|
4633
|
-
CliErrorCode as
|
|
4653
|
+
CliErrorCode as CliErrorCode17,
|
|
4634
4654
|
parseInteractionRequest as parseInteractionRequest2,
|
|
4635
4655
|
parseInteractionResolved as parseInteractionResolved2,
|
|
4636
4656
|
buildConfirm as buildConfirm2,
|
|
@@ -4641,10 +4661,29 @@ import {
|
|
|
4641
4661
|
} from "@hcmai/sdk";
|
|
4642
4662
|
import chalk2 from "chalk";
|
|
4643
4663
|
import * as fs5 from "fs/promises";
|
|
4664
|
+
|
|
4665
|
+
// src/streaming/streamFailureCode.ts
|
|
4666
|
+
import { CliErrorCode as CliErrorCode15 } from "@hcmai/sdk";
|
|
4667
|
+
var CLI_CODES = new Set(Object.values(CliErrorCode15));
|
|
4668
|
+
function cliCodeForStreamFailure(raw) {
|
|
4669
|
+
if (raw === void 0 || raw === null || raw === "") return CliErrorCode15.STREAM_FAILED_NO_SERVER_CODE;
|
|
4670
|
+
if (typeof raw === "string" && CLI_CODES.has(raw)) return raw;
|
|
4671
|
+
return CliErrorCode15.BUSINESS_RULE_VIOLATION;
|
|
4672
|
+
}
|
|
4673
|
+
function serverCodeOf(raw) {
|
|
4674
|
+
if (raw === void 0 || raw === null || raw === "") return void 0;
|
|
4675
|
+
if (typeof raw === "string" && CLI_CODES.has(raw)) return void 0;
|
|
4676
|
+
return String(raw);
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4679
|
+
// src/commands/chat.ts
|
|
4680
|
+
init_exit();
|
|
4681
|
+
init_impersonation_lifecycle();
|
|
4682
|
+
init_auth_guard();
|
|
4644
4683
|
function parseInjectOn(s) {
|
|
4645
4684
|
const fail8 = (detail) => {
|
|
4646
4685
|
throw new CliError16({
|
|
4647
|
-
code:
|
|
4686
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4648
4687
|
message: `--inject-on \u683C\u5F0F <eventType>:<action>[:<arg>]\uFF0Caction \u2208 {interrupt, steer}\uFF08steer \u5FC5\u987B\u5E26 content\uFF09\uFF1B${detail}\uFF0C\u6536\u5230 "${s}"`
|
|
4649
4688
|
});
|
|
4650
4689
|
};
|
|
@@ -4671,20 +4710,20 @@ function parseOnConfirm(s) {
|
|
|
4671
4710
|
if (s === "reject") return { decision: "reject" };
|
|
4672
4711
|
if (s.startsWith("reject:")) return { decision: "reject", reason: s.slice("reject:".length) };
|
|
4673
4712
|
throw new CliError16({
|
|
4674
|
-
code:
|
|
4713
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4675
4714
|
message: `--on-confirm \u53D6\u503C approve | reject | reject:<reason>\uFF0C\u6536\u5230 "${s}"`
|
|
4676
4715
|
});
|
|
4677
4716
|
}
|
|
4678
4717
|
function resolveResumeConversation(args) {
|
|
4679
4718
|
if (args.resume && args.conversation) {
|
|
4680
4719
|
throw new CliError16({
|
|
4681
|
-
code:
|
|
4720
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4682
4721
|
message: "--resume \u548C --conversation \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\uFF1B\u65B0\u547D\u4EE4\u8BF7\u7528 --resume <conversationId>"
|
|
4683
4722
|
});
|
|
4684
4723
|
}
|
|
4685
4724
|
if (args.resume === "NEW") {
|
|
4686
4725
|
throw new CliError16({
|
|
4687
|
-
code:
|
|
4726
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4688
4727
|
message: "--resume \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u8BF7\u76F4\u63A5\u7701\u7565 --resume"
|
|
4689
4728
|
});
|
|
4690
4729
|
}
|
|
@@ -4696,7 +4735,7 @@ function parsePositiveInt(value, fallback, flag) {
|
|
|
4696
4735
|
const n = Number(value ?? fallback);
|
|
4697
4736
|
if (!Number.isInteger(n) || n <= 0) {
|
|
4698
4737
|
throw new CliError16({
|
|
4699
|
-
code:
|
|
4738
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4700
4739
|
message: `${flag} \u9700\u8981\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${value}"`
|
|
4701
4740
|
});
|
|
4702
4741
|
}
|
|
@@ -4720,20 +4759,20 @@ function resolveEventsConversation(args) {
|
|
|
4720
4759
|
const eventConversationId = typeof args.events === "string" ? args.events.trim() : void 0;
|
|
4721
4760
|
if (eventConversationId === "NEW") {
|
|
4722
4761
|
throw new CliError16({
|
|
4723
|
-
code:
|
|
4762
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4724
4763
|
message: "--events \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u6CA1\u6709\u53EF\u67E5\u8BE2\u7684\u4E8B\u4EF6\u6D41"
|
|
4725
4764
|
});
|
|
4726
4765
|
}
|
|
4727
4766
|
if (eventConversationId && resumeConversationId && eventConversationId !== resumeConversationId) {
|
|
4728
4767
|
throw new CliError16({
|
|
4729
|
-
code:
|
|
4768
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4730
4769
|
message: "--events <conversationId> \u4E0E --resume/--conversation \u6307\u5411\u4E0D\u540C\u4F1A\u8BDD\uFF1B\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A id"
|
|
4731
4770
|
});
|
|
4732
4771
|
}
|
|
4733
4772
|
const id = eventConversationId || resumeConversationId;
|
|
4734
4773
|
if (!id) {
|
|
4735
4774
|
throw new CliError16({
|
|
4736
|
-
code:
|
|
4775
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4737
4776
|
message: "\u67E5\u8BE2\u4E8B\u4EF6\u6D41\u8BF7\u4F20 `hcm chat --events <conversationId>`\uFF0C\u6216 `hcm chat --resume <conversationId> --events`"
|
|
4738
4777
|
});
|
|
4739
4778
|
}
|
|
@@ -4875,7 +4914,7 @@ async function printConversationEvents(conversationId, args) {
|
|
|
4875
4914
|
async function printConversationList(args) {
|
|
4876
4915
|
if (args.events || args.resume || args.conversation || args.regenerateFrom || args.promptFile) {
|
|
4877
4916
|
throw new CliError16({
|
|
4878
|
-
code:
|
|
4917
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4879
4918
|
message: "--list \u53EA\u7528\u4E8E\u5217\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 --events/--resume/--conversation/--regenerate-from/--prompt-file"
|
|
4880
4919
|
});
|
|
4881
4920
|
}
|
|
@@ -4906,7 +4945,7 @@ async function chatCommand(prompt, args) {
|
|
|
4906
4945
|
if (args.list) {
|
|
4907
4946
|
if (prompt) {
|
|
4908
4947
|
throw new CliError16({
|
|
4909
|
-
code:
|
|
4948
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4910
4949
|
message: "--list \u4E0D\u63A5\u53D7 prompt\uFF1B\u7528 `hcm chat --list` \u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD"
|
|
4911
4950
|
});
|
|
4912
4951
|
}
|
|
@@ -4918,7 +4957,7 @@ async function chatCommand(prompt, args) {
|
|
|
4918
4957
|
if (eventsConversationId) {
|
|
4919
4958
|
if (prompt || args.promptFile || args.regenerateFrom || args.attach?.length) {
|
|
4920
4959
|
throw new CliError16({
|
|
4921
|
-
code:
|
|
4960
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4922
4961
|
message: "--events \u662F\u53EA\u8BFB\u67E5\u8BE2\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 prompt/--prompt-file/--regenerate-from/--attach"
|
|
4923
4962
|
});
|
|
4924
4963
|
}
|
|
@@ -4937,14 +4976,14 @@ async function chatCommand(prompt, args) {
|
|
|
4937
4976
|
regenerateFromSeq = Number(args.regenerateFrom);
|
|
4938
4977
|
if (!Number.isInteger(regenerateFromSeq) || regenerateFromSeq <= 0) {
|
|
4939
4978
|
throw new CliError16({
|
|
4940
|
-
code:
|
|
4979
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4941
4980
|
message: `--regenerate-from \u9700\u8981\u6B63\u6574\u6570 journal seq \u6216 last-assistant\uFF0C\u6536\u5230 "${args.regenerateFrom}"`
|
|
4942
4981
|
});
|
|
4943
4982
|
}
|
|
4944
4983
|
}
|
|
4945
4984
|
if (!requestedConversationId) {
|
|
4946
4985
|
throw new CliError16({
|
|
4947
|
-
code:
|
|
4986
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4948
4987
|
message: "--regenerate-from \u5FC5\u987B\u914D\u5408 --resume <\u65E2\u5B58\u4F1A\u8BDD id>\uFF08\u91CD\u8DD1\u65E2\u5B58\u6BB5\uFF0C\u65E0\u65B0 prompt\uFF09"
|
|
4949
4988
|
});
|
|
4950
4989
|
}
|
|
@@ -4959,7 +4998,7 @@ async function chatCommand(prompt, args) {
|
|
|
4959
4998
|
}
|
|
4960
4999
|
if (prompt === void 0 || !prompt && !regenerateMode) {
|
|
4961
5000
|
throw new CliError16({
|
|
4962
|
-
code:
|
|
5001
|
+
code: CliErrorCode17.INVALID_ARGUMENT,
|
|
4963
5002
|
message: "prompt is required (positional or --prompt-file)"
|
|
4964
5003
|
});
|
|
4965
5004
|
}
|
|
@@ -4982,7 +5021,7 @@ async function chatCommand(prompt, args) {
|
|
|
4982
5021
|
const target = findLastAssistantTarget(items);
|
|
4983
5022
|
if (target.seq == null) {
|
|
4984
5023
|
throw new CliError16({
|
|
4985
|
-
code:
|
|
5024
|
+
code: CliErrorCode17.BUSINESS_RULE_VIOLATION,
|
|
4986
5025
|
message: `--regenerate-from last-assistant \u627E\u4E0D\u5230\u53EF\u91CD\u8DD1\u7684 chat-text seq: conversation=${resumeConversationId}\uFF08${lastAssistantMissDetail(target)}\uFF09`
|
|
4987
5026
|
});
|
|
4988
5027
|
}
|
|
@@ -4991,7 +5030,11 @@ async function chatCommand(prompt, args) {
|
|
|
4991
5030
|
const ws = new WsClient2({
|
|
4992
5031
|
endpoint: wsUrl,
|
|
4993
5032
|
getAccessToken: () => client3.getAccessToken(),
|
|
4994
|
-
onTokenExpiring: () => client3.handleRefresh()
|
|
5033
|
+
onTokenExpiring: () => client3.handleRefresh(),
|
|
5034
|
+
// issue #257:握手带上会话 id,后端才会绑控制通道并重投上次留下的未决暂停。
|
|
5035
|
+
// 会话 id 在上面几十行就定下来了(--resume 或刚 createConversation 出来的),
|
|
5036
|
+
// 建连时它一定已经就位。
|
|
5037
|
+
conversationId: resumeConversationId
|
|
4995
5038
|
});
|
|
4996
5039
|
await ws.connect();
|
|
4997
5040
|
const fmt = args.output ?? "text";
|
|
@@ -5012,7 +5055,13 @@ async function chatCommand(prompt, args) {
|
|
|
5012
5055
|
});
|
|
5013
5056
|
const presenter = new StreamPresenter2(renderer, {
|
|
5014
5057
|
showToolCalls: args.showToolCalls !== false,
|
|
5015
|
-
output: fmt
|
|
5058
|
+
output: fmt,
|
|
5059
|
+
// issue #255:真因走的是连接层帧 `{type:'error',code,message}`,不在 v4 事件里——
|
|
5060
|
+
// `MessageStopPayload` 这个 record 只有 (stopReason, parentToolUseId, *Tokens),
|
|
5061
|
+
// 没有 errorCode 也没有 message。handle 在下面才建(同一个 async 函数体内),但这个闭包只在
|
|
5062
|
+
// `presenter.consume(handle.events)` 里被调到,那时它早就有了。
|
|
5063
|
+
serverError: () => handle.serverError()
|
|
5064
|
+
// 可等待:真因晚一个 tick 才到(issue #255)
|
|
5016
5065
|
});
|
|
5017
5066
|
if (resumedExisting && isTty && fmt === "text" && !args.raw) {
|
|
5018
5067
|
const { fetchConversationTimeline: fetchConversationTimeline3, buildResumeSummary: buildResumeSummary2 } = await import("@hcmai/sdk");
|
|
@@ -5203,10 +5252,12 @@ async function chatCommand(prompt, args) {
|
|
|
5203
5252
|
} catch (e) {
|
|
5204
5253
|
process.removeListener("SIGINT", sigintHandler);
|
|
5205
5254
|
await ws.close();
|
|
5255
|
+
const serverCode = serverCodeOf(e.code);
|
|
5206
5256
|
throw new CliError16({
|
|
5207
|
-
code: e.code
|
|
5257
|
+
code: cliCodeForStreamFailure(e.code),
|
|
5208
5258
|
message: e.message,
|
|
5209
|
-
traceId: e.traceId ?? void 0
|
|
5259
|
+
traceId: e.traceId ?? void 0,
|
|
5260
|
+
...serverCode ? { context: { responseCode: serverCode } } : {}
|
|
5210
5261
|
});
|
|
5211
5262
|
}
|
|
5212
5263
|
}
|
|
@@ -5266,15 +5317,210 @@ async function chatCommand(prompt, args) {
|
|
|
5266
5317
|
}
|
|
5267
5318
|
}
|
|
5268
5319
|
|
|
5320
|
+
// src/commands/interactions.ts
|
|
5321
|
+
init_exit();
|
|
5322
|
+
init_auth_guard();
|
|
5323
|
+
import {
|
|
5324
|
+
CliError as CliError17,
|
|
5325
|
+
CliErrorCode as CliErrorCode18,
|
|
5326
|
+
DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4,
|
|
5327
|
+
HcmClient as HcmClient12,
|
|
5328
|
+
WsClient as WsClient3,
|
|
5329
|
+
conversationWebSocketEndpoint as conversationWebSocketEndpoint3,
|
|
5330
|
+
assertDangerWrite as assertDangerWrite3,
|
|
5331
|
+
formatObject as formatObject10,
|
|
5332
|
+
formatRows as formatRows4,
|
|
5333
|
+
listPendingInteractions,
|
|
5334
|
+
loadConversationState,
|
|
5335
|
+
respondToInteraction
|
|
5336
|
+
} from "@hcmai/sdk";
|
|
5337
|
+
function resolveConversation(explicit, state) {
|
|
5338
|
+
const given = explicit?.trim();
|
|
5339
|
+
if (given) return { conversationId: given, source: "flag" };
|
|
5340
|
+
const last = state?.lastConversationId?.trim();
|
|
5341
|
+
if (last) return { conversationId: last, source: "state" };
|
|
5342
|
+
throw new CliError17({
|
|
5343
|
+
code: CliErrorCode18.INVALID_ARGUMENT,
|
|
5344
|
+
message: "\u4E0D\u77E5\u9053\u8BE5\u770B\u54EA\u4E2A\u4F1A\u8BDD\uFF1A\u6CA1\u6709\u4F20 --conversation\uFF0C\u672C env \u4E5F\u6CA1\u6709\u4E0A\u4E00\u6B21\u4F1A\u8BDD\u7684\u8BB0\u5F55",
|
|
5345
|
+
context: {
|
|
5346
|
+
nextStep: "\u7528 `hcm chat --list` \u627E\u5230\u4F1A\u8BDD id\uFF0C\u518D `hcm interactions list --conversation <id>`"
|
|
5347
|
+
}
|
|
5348
|
+
});
|
|
5349
|
+
}
|
|
5350
|
+
function decisionFor(action, args) {
|
|
5351
|
+
if (action === "approve") return { kind: "confirm" };
|
|
5352
|
+
if (action === "reject") return { kind: "reject", reason: args.reason?.trim() || void 0 };
|
|
5353
|
+
const answer = args.answer?.trim();
|
|
5354
|
+
if (!answer) {
|
|
5355
|
+
throw new CliError17({
|
|
5356
|
+
code: CliErrorCode18.INVALID_ARGUMENT,
|
|
5357
|
+
message: 'answer \u9700\u8981\u7B54\u6848\u6587\u672C\uFF1A--answer "<\u4F60\u7684\u56DE\u7B54>"',
|
|
5358
|
+
context: {
|
|
5359
|
+
nextStep: "\u9009\u9879\u578B\u8FFD\u95EE\u4E5F\u8981\u628A\u9009\u4E2D\u7684\u90A3\u9879\u539F\u6587\u5199\u8FDB --answer\uFF1B--choice \u53EA\u662F\u8865\u5145\uFF0C\u5355\u72EC\u7ED9\u4F1A\u88AB\u4E0B\u6E38\u5F53\u6210\u672A\u56DE\u7B54"
|
|
5360
|
+
}
|
|
5361
|
+
});
|
|
5362
|
+
}
|
|
5363
|
+
let choiceIndex;
|
|
5364
|
+
if (args.choice !== void 0 && String(args.choice).trim() !== "") {
|
|
5365
|
+
choiceIndex = Number(args.choice);
|
|
5366
|
+
if (!Number.isInteger(choiceIndex)) {
|
|
5367
|
+
throw new CliError17({
|
|
5368
|
+
code: CliErrorCode18.INVALID_ARGUMENT,
|
|
5369
|
+
message: `--choice \u8981\u6574\u6570\u4E0B\u6807\uFF0C\u6536\u5230\uFF1A${args.choice}`,
|
|
5370
|
+
context: { nextStep: "\u4E0B\u6807\u6765\u81EA ASK \u4E8B\u4EF6 choices \u6570\u7EC4\u7684\u4F4D\u7F6E\uFF08\u4ECE 0 \u8D77\uFF09" }
|
|
5371
|
+
});
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
return { kind: "answer", answer, choiceIndex };
|
|
5375
|
+
}
|
|
5376
|
+
function renderPendingTable(rows2, conversationId) {
|
|
5377
|
+
if (!rows2.length) {
|
|
5378
|
+
return `\u4F1A\u8BDD ${conversationId} \u4E0A\u6CA1\u6709\u672A\u51B3\u7684\u6682\u505C\u3002
|
|
5379
|
+
\uFF08\u8FD9\u4E0E\u300C\u770B\u9519\u4F1A\u8BDD\u4E86\u300D\u662F\u540C\u4E00\u4E2A\u753B\u9762\uFF1A\u7528 \`hcm chat --list\` \u6838\u4E00\u4E0B id\uFF1B\u6682\u505C\u9ED8\u8BA4 5 \u5206\u949F\u8FC7\u671F\uFF0C\u8FC7\u671F\u7684\u4E0D\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\u3002\uFF09`;
|
|
5380
|
+
}
|
|
5381
|
+
const table = formatRows4(
|
|
5382
|
+
rows2.map((r) => ({
|
|
5383
|
+
ID: r.interactionId,
|
|
5384
|
+
TYPE: r.type,
|
|
5385
|
+
TOOL: r.executorName || "-",
|
|
5386
|
+
RISK: r.riskLevel || "-",
|
|
5387
|
+
SUMMARY: r.operationSummary || "(\u65E0\u64CD\u4F5C\u6458\u8981)",
|
|
5388
|
+
EXPIRES: r.expired ? `${r.expiresAt || "-"} \u5DF2\u8FC7\u671F` : r.expiresAt || "-"
|
|
5389
|
+
})),
|
|
5390
|
+
{ format: "table" }
|
|
5391
|
+
);
|
|
5392
|
+
const live = rows2.filter((r) => !r.expired);
|
|
5393
|
+
const kinds = new Set(live.map((r) => r.type));
|
|
5394
|
+
const verbs = [];
|
|
5395
|
+
if (kinds.has("CONFIRM")) {
|
|
5396
|
+
verbs.push(`hcm interactions approve <ID> --conversation ${conversationId}`, "\uFF08\u62D2\u7EDD\u6362 reject\uFF09");
|
|
5397
|
+
}
|
|
5398
|
+
if (kinds.has("ASK")) {
|
|
5399
|
+
verbs.push(`hcm interactions answer <ID> --answer "<\u4F60\u7684\u56DE\u7B54>" --conversation ${conversationId}`);
|
|
5400
|
+
}
|
|
5401
|
+
if (live.length && !verbs.length) {
|
|
5402
|
+
verbs.push(
|
|
5403
|
+
`\u672A\u8BC6\u522B\u7684\u6682\u505C\u7C7B\u578B ${[...kinds].join(" / ")}\uFF1A\u672C\u7248 CLI \u53EA\u5904\u7406 CONFIRM / ASK\uFF0C\u8BF7\u5728\u524D\u7AEF\u90A3\u5F20\u5361\u4E0A\u5904\u7406\uFF0C\u6216\u5347\u7EA7 CLI\uFF08hcm upgrade\uFF09`
|
|
5404
|
+
);
|
|
5405
|
+
}
|
|
5406
|
+
const hint = live.length ? `
|
|
5407
|
+
\u4E0B\u4E00\u6B65\uFF1A${verbs.join("\n ")}` : "\n\u5168\u90E8\u5DF2\u8FC7\u671F\uFF1A\u8FC7\u671F\u7684\u6682\u505C\u70B9\u4E0D\u52A8\u4E86\uFF0C\u91CD\u53D1\u539F\u59CB\u6307\u4EE4\u5373\u53EF\u3002";
|
|
5408
|
+
return `${table}
|
|
5409
|
+
\u5171 ${rows2.length} \u6761\uFF0C\u5176\u4E2D ${live.length} \u6761\u4ECD\u53EF\u5904\u7406\u3002${hint}`;
|
|
5410
|
+
}
|
|
5411
|
+
function renderOutcome(o) {
|
|
5412
|
+
const head = `${o.interactionId} \xB7 decision=${o.decision ?? "-"} status=${o.status ?? "-"}`;
|
|
5413
|
+
if (o.status === "SUPERSEDED") {
|
|
5414
|
+
return `${head}
|
|
5415
|
+
\u8FD9\u6761\u6682\u505C\u88AB\u65B0\u7684\u6682\u505C\u63A5\u7BA1\u4E86\uFF08\u7EED\u8DD1\u9014\u4E2D\u53C8\u5F39\u4E86\u4E00\u4E2A\uFF09\u2014\u2014\u4F60\u8981\u529E\u7684\u4E8B\u8FD8\u6CA1\u529E\u5B8C\u3002
|
|
5416
|
+
\u4E0B\u4E00\u6B65\uFF1A\u518D \`hcm interactions list\` \u4E00\u6B21\uFF0C\u5904\u7406\u65B0\u51FA\u73B0\u7684\u90A3\u6761\u3002`;
|
|
5417
|
+
}
|
|
5418
|
+
if (o.status === "FAILED") {
|
|
5419
|
+
return `${head}
|
|
5420
|
+
${o.text ?? "(\u540E\u7AEF\u6CA1\u6709\u7ED9\u6536\u5C3E\u6B63\u6587)"}
|
|
5421
|
+
\u7EED\u8DD1\u5931\u8D25\uFF1A\u51B3\u5B9A\u5DF2\u7ECF\u53D7\u7406\uFF0C\u4F46\u6267\u884C\u6CA1\u6210\u529F\u3002`;
|
|
5422
|
+
}
|
|
5423
|
+
return `${head}
|
|
5424
|
+
${o.text ?? "(\u540E\u7AEF\u6CA1\u6709\u7ED9\u6536\u5C3E\u6B63\u6587)"}`;
|
|
5425
|
+
}
|
|
5426
|
+
async function loadState(env2) {
|
|
5427
|
+
try {
|
|
5428
|
+
return await loadConversationState(env2);
|
|
5429
|
+
} catch {
|
|
5430
|
+
return null;
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
function announceSource(source, conversationId, json) {
|
|
5434
|
+
if (source === "state" && !json) {
|
|
5435
|
+
process.stderr.write(`\u21BB \u672A\u6307\u5B9A --conversation\uFF0C\u7528\u672C env \u4E0A\u4E00\u6B21\u7684\u4F1A\u8BDD\uFF1A${conversationId}
|
|
5436
|
+
`);
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5439
|
+
async function interactionsListCommand(args) {
|
|
5440
|
+
try {
|
|
5441
|
+
const ctx = await getActiveAuthContextFromCli(args);
|
|
5442
|
+
const { conversationId, source } = resolveConversation(
|
|
5443
|
+
args.conversation,
|
|
5444
|
+
await loadState(ctx.env)
|
|
5445
|
+
);
|
|
5446
|
+
const json = args.output === "json";
|
|
5447
|
+
announceSource(source, conversationId, json);
|
|
5448
|
+
const client3 = HcmClient12.fromAuthContext(ctx);
|
|
5449
|
+
const agentId = args.agent ?? DEFAULT_AGENT_ID4;
|
|
5450
|
+
const rows2 = await listPendingInteractions(client3.raw(), agentId, conversationId);
|
|
5451
|
+
if (json) {
|
|
5452
|
+
process.stdout.write(
|
|
5453
|
+
formatObject10(
|
|
5454
|
+
{ conversationId, conversationIdSource: source, count: rows2.length, interactions: rows2 },
|
|
5455
|
+
{ format: "json" }
|
|
5456
|
+
) + "\n"
|
|
5457
|
+
);
|
|
5458
|
+
} else {
|
|
5459
|
+
process.stdout.write(renderPendingTable(rows2, conversationId) + "\n");
|
|
5460
|
+
}
|
|
5461
|
+
process.exitCode = 0;
|
|
5462
|
+
} catch (e) {
|
|
5463
|
+
exitWithError(e);
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5466
|
+
async function interactionsRespondCommand(action, interactionId, args) {
|
|
5467
|
+
let ws;
|
|
5468
|
+
try {
|
|
5469
|
+
const decision = decisionFor(action, args);
|
|
5470
|
+
const ctx = await getActiveAuthContextFromCli(args);
|
|
5471
|
+
const { conversationId, source } = resolveConversation(
|
|
5472
|
+
args.conversation,
|
|
5473
|
+
await loadState(ctx.env)
|
|
5474
|
+
);
|
|
5475
|
+
const json = args.output === "json";
|
|
5476
|
+
announceSource(source, conversationId, json);
|
|
5477
|
+
assertDangerWrite3(ctx.environmentSafety, "\u56DE\u5E94\u6682\u505C\uFF08\u6279\u51C6\u4F1A\u771F\u7684\u6267\u884C\u90A3\u4E2A\u5199\u64CD\u4F5C\uFF09");
|
|
5478
|
+
const client3 = HcmClient12.fromAuthContext(ctx);
|
|
5479
|
+
ws = new WsClient3({
|
|
5480
|
+
endpoint: conversationWebSocketEndpoint3(ctx.endpoint),
|
|
5481
|
+
getAccessToken: () => client3.getAccessToken(),
|
|
5482
|
+
onTokenExpiring: () => client3.handleRefresh(),
|
|
5483
|
+
conversationId
|
|
5484
|
+
});
|
|
5485
|
+
await ws.connect();
|
|
5486
|
+
const timeoutMs = args.timeout ? Number(args.timeout) * 1e3 : void 0;
|
|
5487
|
+
if (timeoutMs !== void 0 && !Number.isFinite(timeoutMs)) {
|
|
5488
|
+
throw new CliError17({
|
|
5489
|
+
code: CliErrorCode18.INVALID_ARGUMENT,
|
|
5490
|
+
message: `--timeout \u8981\u79D2\u6570\uFF0C\u6536\u5230\uFF1A${args.timeout}`
|
|
5491
|
+
});
|
|
5492
|
+
}
|
|
5493
|
+
const outcome = await respondToInteraction(ws, {
|
|
5494
|
+
conversationId,
|
|
5495
|
+
interactionId,
|
|
5496
|
+
decision,
|
|
5497
|
+
timeoutMs,
|
|
5498
|
+
onAccepted: () => {
|
|
5499
|
+
if (!json) process.stderr.write("\xB7 \u5DF2\u53D7\u7406\uFF0C\u7EED\u8DD1\u4E2D\u2026\n");
|
|
5500
|
+
}
|
|
5501
|
+
});
|
|
5502
|
+
if (json) {
|
|
5503
|
+
process.stdout.write(formatObject10(outcome, { format: "json" }) + "\n");
|
|
5504
|
+
} else {
|
|
5505
|
+
process.stdout.write(renderOutcome(outcome) + "\n");
|
|
5506
|
+
}
|
|
5507
|
+
process.exitCode = outcome.status === "COMPLETED" ? 0 : 1;
|
|
5508
|
+
} catch (e) {
|
|
5509
|
+
exitWithError(e);
|
|
5510
|
+
} finally {
|
|
5511
|
+
await ws?.close();
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
|
|
5269
5515
|
// src/commands/download.ts
|
|
5270
5516
|
init_auth_guard();
|
|
5271
5517
|
init_exit();
|
|
5272
5518
|
import { downloadDocument } from "@hcmai/sdk";
|
|
5273
|
-
import { HcmClient as
|
|
5519
|
+
import { HcmClient as HcmClient13 } from "@hcmai/sdk";
|
|
5274
5520
|
async function downloadCommand(documentId, args) {
|
|
5275
5521
|
try {
|
|
5276
5522
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
5277
|
-
const client3 =
|
|
5523
|
+
const client3 = HcmClient13.fromAuthContext(ctx);
|
|
5278
5524
|
const saved = await downloadDocument(client3.raw(), { documentId }, args.output);
|
|
5279
5525
|
process.stdout.write(saved + "\n");
|
|
5280
5526
|
process.exitCode = 0;
|
|
@@ -5296,15 +5542,15 @@ init_auth_guard();
|
|
|
5296
5542
|
init_exit();
|
|
5297
5543
|
import {
|
|
5298
5544
|
deleteDocument,
|
|
5299
|
-
HcmClient as
|
|
5545
|
+
HcmClient as HcmClient14,
|
|
5300
5546
|
fromAxiosError as fromAxiosError11,
|
|
5301
|
-
formatObject as
|
|
5547
|
+
formatObject as formatObject11
|
|
5302
5548
|
} from "@hcmai/sdk";
|
|
5303
5549
|
async function documentDeleteCommand(documentId, args) {
|
|
5304
5550
|
try {
|
|
5305
|
-
const client3 =
|
|
5551
|
+
const client3 = HcmClient14.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
5306
5552
|
await deleteDocument(client3.raw(), documentId);
|
|
5307
|
-
process.stdout.write(
|
|
5553
|
+
process.stdout.write(formatObject11({ success: true, documentId }, { format: args.output ?? "json" }) + "\n");
|
|
5308
5554
|
process.exitCode = 0;
|
|
5309
5555
|
} catch (e) {
|
|
5310
5556
|
const err = e;
|
|
@@ -5316,7 +5562,7 @@ async function documentDeleteCommand(documentId, args) {
|
|
|
5316
5562
|
// src/commands/trace.ts
|
|
5317
5563
|
init_exit();
|
|
5318
5564
|
init_auth_guard();
|
|
5319
|
-
import { HcmClient as
|
|
5565
|
+
import { HcmClient as HcmClient15, formatObject as formatObject12, formatRows as formatRows5, fromAxiosError as fromAxiosError12 } from "@hcmai/sdk";
|
|
5320
5566
|
function parsePositiveInt2(value, fallback, flag) {
|
|
5321
5567
|
const n = Number(value ?? fallback);
|
|
5322
5568
|
if (!Number.isInteger(n) || n <= 0) {
|
|
@@ -5369,7 +5615,7 @@ function printRecent(data, limit) {
|
|
|
5369
5615
|
OPERATION: short(t.rootOperation, 36),
|
|
5370
5616
|
TRACE: t.traceId ?? "-"
|
|
5371
5617
|
}));
|
|
5372
|
-
process.stdout.write(
|
|
5618
|
+
process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
|
|
5373
5619
|
process.stdout.write(`Showing ${rows2.length} trace${rows2.length === 1 ? "" : "s"}.
|
|
5374
5620
|
`);
|
|
5375
5621
|
process.stdout.write("next: hcm trace <traceId> | hcm trace <traceId> --events | hcm trace <traceId> --raw\n");
|
|
@@ -5400,7 +5646,7 @@ function printTraceDetail(traceId, agg) {
|
|
|
5400
5646
|
OPERATION: short(sp.operation, 48)
|
|
5401
5647
|
}));
|
|
5402
5648
|
process.stdout.write("\nTempo spans:\n");
|
|
5403
|
-
process.stdout.write(
|
|
5649
|
+
process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
|
|
5404
5650
|
if (spans.length > rows2.length) process.stdout.write(`... ${spans.length - rows2.length} more spans
|
|
5405
5651
|
`);
|
|
5406
5652
|
} else if (tempo?.reason) {
|
|
@@ -5415,7 +5661,7 @@ Tempo: ${tempo.reason}
|
|
|
5415
5661
|
MESSAGE: short(log.msg ?? log.exception, 90)
|
|
5416
5662
|
}));
|
|
5417
5663
|
process.stdout.write("\nLoki logs:\n");
|
|
5418
|
-
process.stdout.write(
|
|
5664
|
+
process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
|
|
5419
5665
|
if (logs.length > rows2.length) process.stdout.write(`... ${logs.length - rows2.length} more logs
|
|
5420
5666
|
`);
|
|
5421
5667
|
} else if (loki?.reason) {
|
|
@@ -5453,7 +5699,7 @@ function printTraceEvents(traceId, agg) {
|
|
|
5453
5699
|
}));
|
|
5454
5700
|
process.stdout.write(`trace events: ${traceId}
|
|
5455
5701
|
`);
|
|
5456
|
-
process.stdout.write(
|
|
5702
|
+
process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
|
|
5457
5703
|
}
|
|
5458
5704
|
async function listRecentTraces(client3, limit) {
|
|
5459
5705
|
const http = client3.raw();
|
|
@@ -5501,7 +5747,7 @@ async function listRecentConversationsPg(client3, limit) {
|
|
|
5501
5747
|
TOKENS: c.totalTokens ?? "-",
|
|
5502
5748
|
CONV: c.id ?? "-"
|
|
5503
5749
|
}));
|
|
5504
|
-
process.stdout.write(
|
|
5750
|
+
process.stdout.write(formatRows5(table, { format: "table" }) + "\n");
|
|
5505
5751
|
process.stdout.write(`Showing ${rows2.length} conversation${rows2.length === 1 ? "" : "s"}\uFF08PG \u89C6\u56FE\uFF09\u3002
|
|
5506
5752
|
`);
|
|
5507
5753
|
process.stdout.write("next: hcm trace --conv <CONV>\uFF08\u770B\u8BE5\u4F1A\u8BDD LLM \u9010\u8C03\u7528\uFF0C\u542B\u59D4\u6D3E\u5B50\u4F1A\u8BDD\uFF09\n");
|
|
@@ -5584,7 +5830,7 @@ ${" ".repeat(node.depth)}\u2514\u2500 \u59D4\u6D3E \u2192 ${node.label} \xB7 ${
|
|
|
5584
5830
|
|
|
5585
5831
|
`);
|
|
5586
5832
|
if (table.length) {
|
|
5587
|
-
process.stdout.write(
|
|
5833
|
+
process.stdout.write(formatRows5(table, { format: "table" }) + "\n");
|
|
5588
5834
|
} else {
|
|
5589
5835
|
const why = envelopeReason(node.envelope);
|
|
5590
5836
|
process.stdout.write(`\uFF08\u65E0 LLM \u8C03\u7528${why ? ` \xB7 ${short(why, 60)}` : ""}\uFF09
|
|
@@ -5711,14 +5957,14 @@ async function gatherLlmTraceTree(http, rootConvId, maxDepth = 3) {
|
|
|
5711
5957
|
}
|
|
5712
5958
|
async function traceCommand(traceId, args) {
|
|
5713
5959
|
try {
|
|
5714
|
-
const client3 =
|
|
5960
|
+
const client3 = HcmClient15.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
5715
5961
|
const http = client3.raw();
|
|
5716
5962
|
const convId = args.conv ?? (args.llmCalls ? traceId ?? void 0 : void 0);
|
|
5717
5963
|
if (convId) {
|
|
5718
5964
|
if (args.raw || args.output === "json" || args.output === "yaml") {
|
|
5719
5965
|
const body = await fetchLlmTrace(http, convId);
|
|
5720
5966
|
const fmt = args.raw ? "json" : args.output;
|
|
5721
|
-
process.stdout.write(
|
|
5967
|
+
process.stdout.write(formatObject12(body.rows, { format: fmt }) + "\n");
|
|
5722
5968
|
if (!body.rows.length) {
|
|
5723
5969
|
for (const line of describeLlmTraceEmpty(convId, body.envelope)) {
|
|
5724
5970
|
process.stderr.write(line + "\n");
|
|
@@ -5743,12 +5989,12 @@ async function traceCommand(traceId, args) {
|
|
|
5743
5989
|
const resp = await http.get(`/api/trace/${traceId}`);
|
|
5744
5990
|
const agg = resp.data ?? {};
|
|
5745
5991
|
if (args.raw) {
|
|
5746
|
-
process.stdout.write(
|
|
5992
|
+
process.stdout.write(formatObject12(agg, { format: "json" }) + "\n");
|
|
5747
5993
|
process.exitCode = 0;
|
|
5748
5994
|
return;
|
|
5749
5995
|
}
|
|
5750
5996
|
if (args.output === "json" || args.output === "yaml") {
|
|
5751
|
-
process.stdout.write(
|
|
5997
|
+
process.stdout.write(formatObject12(agg, { format: args.output }) + "\n");
|
|
5752
5998
|
process.exitCode = 0;
|
|
5753
5999
|
return;
|
|
5754
6000
|
}
|
|
@@ -5759,7 +6005,7 @@ async function traceCommand(traceId, args) {
|
|
|
5759
6005
|
exitWithError(`Span #${args.span} \u8D8A\u754C\uFF08\u5171 ${spans.length} \u6761 Tempo span\uFF09`);
|
|
5760
6006
|
return;
|
|
5761
6007
|
}
|
|
5762
|
-
process.stdout.write(
|
|
6008
|
+
process.stdout.write(formatObject12(spans[idx], { format: "yaml" }) + "\n");
|
|
5763
6009
|
process.exitCode = 0;
|
|
5764
6010
|
return;
|
|
5765
6011
|
}
|
|
@@ -5783,21 +6029,21 @@ async function traceCommand(traceId, args) {
|
|
|
5783
6029
|
init_exit();
|
|
5784
6030
|
init_auth_guard();
|
|
5785
6031
|
import {
|
|
5786
|
-
HcmClient as
|
|
5787
|
-
formatObject as
|
|
6032
|
+
HcmClient as HcmClient16,
|
|
6033
|
+
formatObject as formatObject13,
|
|
5788
6034
|
fromAxiosError as fromAxiosError13,
|
|
5789
6035
|
getCacheStats,
|
|
5790
6036
|
clearModelCache,
|
|
5791
6037
|
clearMetaCache
|
|
5792
6038
|
} from "@hcmai/sdk";
|
|
5793
6039
|
async function withClient(args, fn) {
|
|
5794
|
-
const client3 =
|
|
6040
|
+
const client3 = HcmClient16.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
5795
6041
|
return fn(client3);
|
|
5796
6042
|
}
|
|
5797
6043
|
function emit(result, args, human) {
|
|
5798
6044
|
const fmt = args.output ?? "json";
|
|
5799
6045
|
if (fmt !== "json") process.stdout.write(human + "\n");
|
|
5800
|
-
process.stdout.write(
|
|
6046
|
+
process.stdout.write(formatObject13(result, { format: fmt }) + "\n");
|
|
5801
6047
|
process.exitCode = 0;
|
|
5802
6048
|
return;
|
|
5803
6049
|
}
|
|
@@ -5841,8 +6087,8 @@ init_exit();
|
|
|
5841
6087
|
init_auth_guard();
|
|
5842
6088
|
import { readFileSync as readFileSync3 } from "fs";
|
|
5843
6089
|
import {
|
|
5844
|
-
HcmClient as
|
|
5845
|
-
formatObject as
|
|
6090
|
+
HcmClient as HcmClient17,
|
|
6091
|
+
formatObject as formatObject14,
|
|
5846
6092
|
fromAxiosError as fromAxiosError14,
|
|
5847
6093
|
scriptDryRun,
|
|
5848
6094
|
validateScriptManifest,
|
|
@@ -5850,13 +6096,13 @@ import {
|
|
|
5850
6096
|
getScriptTask
|
|
5851
6097
|
} from "@hcmai/sdk";
|
|
5852
6098
|
async function withClient2(args, fn) {
|
|
5853
|
-
const client3 =
|
|
6099
|
+
const client3 = HcmClient17.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
5854
6100
|
return fn(client3);
|
|
5855
6101
|
}
|
|
5856
6102
|
function emit2(result, args, human) {
|
|
5857
6103
|
const fmt = args.output ?? "json";
|
|
5858
6104
|
if (fmt !== "json") process.stdout.write(human + "\n");
|
|
5859
|
-
process.stdout.write(
|
|
6105
|
+
process.stdout.write(formatObject14(result, { format: fmt }) + "\n");
|
|
5860
6106
|
process.exitCode = 0;
|
|
5861
6107
|
return;
|
|
5862
6108
|
}
|
|
@@ -5952,8 +6198,8 @@ async function scriptTaskCommand(taskId, args) {
|
|
|
5952
6198
|
init_exit();
|
|
5953
6199
|
init_auth_guard();
|
|
5954
6200
|
import {
|
|
5955
|
-
HcmClient as
|
|
5956
|
-
formatObject as
|
|
6201
|
+
HcmClient as HcmClient18,
|
|
6202
|
+
formatObject as formatObject15,
|
|
5957
6203
|
fromAxiosError as fromAxiosError15,
|
|
5958
6204
|
uploadDocument as uploadDocument2
|
|
5959
6205
|
} from "@hcmai/sdk";
|
|
@@ -5961,7 +6207,7 @@ var DEFAULT_UPLOAD_CATEGORY = "attachment";
|
|
|
5961
6207
|
async function uploadCommand(filePath, args) {
|
|
5962
6208
|
try {
|
|
5963
6209
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
5964
|
-
const client3 =
|
|
6210
|
+
const client3 = HcmClient18.fromAuthContext(ctx);
|
|
5965
6211
|
const meta2 = await uploadDocument2(
|
|
5966
6212
|
client3.raw(),
|
|
5967
6213
|
filePath,
|
|
@@ -5974,7 +6220,7 @@ async function uploadCommand(filePath, args) {
|
|
|
5974
6220
|
`
|
|
5975
6221
|
);
|
|
5976
6222
|
}
|
|
5977
|
-
process.stdout.write(
|
|
6223
|
+
process.stdout.write(formatObject15(meta2, { format: fmt }) + "\n");
|
|
5978
6224
|
process.exitCode = 0;
|
|
5979
6225
|
return;
|
|
5980
6226
|
} catch (e) {
|
|
@@ -5996,8 +6242,8 @@ async function uploadCommand(filePath, args) {
|
|
|
5996
6242
|
init_exit();
|
|
5997
6243
|
init_auth_guard();
|
|
5998
6244
|
import {
|
|
5999
|
-
HcmClient as
|
|
6000
|
-
formatObject as
|
|
6245
|
+
HcmClient as HcmClient19,
|
|
6246
|
+
formatObject as formatObject16,
|
|
6001
6247
|
fromAxiosError as fromAxiosError16,
|
|
6002
6248
|
packDataPackage,
|
|
6003
6249
|
installDataPackageArtifactAsync,
|
|
@@ -6023,7 +6269,7 @@ async function datapackagePackCommand(packageDir, args) {
|
|
|
6023
6269
|
`
|
|
6024
6270
|
);
|
|
6025
6271
|
}
|
|
6026
|
-
process.stdout.write(
|
|
6272
|
+
process.stdout.write(formatObject16(result, { format: fmt }) + "\n");
|
|
6027
6273
|
process.exitCode = 0;
|
|
6028
6274
|
return;
|
|
6029
6275
|
} catch (e) {
|
|
@@ -6033,7 +6279,7 @@ async function datapackagePackCommand(packageDir, args) {
|
|
|
6033
6279
|
async function datapackageInstallCommand(artifactPath, args) {
|
|
6034
6280
|
try {
|
|
6035
6281
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
6036
|
-
const client3 =
|
|
6282
|
+
const client3 = HcmClient19.fromAuthContext(ctx);
|
|
6037
6283
|
const fmt = args.output ?? "json";
|
|
6038
6284
|
const human = fmt !== "json";
|
|
6039
6285
|
const accepted = await installDataPackageArtifactAsync(client3, artifactPath, {
|
|
@@ -6110,7 +6356,7 @@ async function datapackageInstallCommand(artifactPath, args) {
|
|
|
6110
6356
|
async function datapackageStatusCommand(runId, args) {
|
|
6111
6357
|
try {
|
|
6112
6358
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
6113
|
-
const client3 =
|
|
6359
|
+
const client3 = HcmClient19.fromAuthContext(ctx);
|
|
6114
6360
|
const run3 = await fetchInstallRun(client3, runId);
|
|
6115
6361
|
const fmt = args.output ?? "json";
|
|
6116
6362
|
if (!run3) {
|
|
@@ -6150,7 +6396,7 @@ function truncateTail(text, max) {
|
|
|
6150
6396
|
return text.length <= max ? text : "\u2026" + text.slice(text.length - max + 1);
|
|
6151
6397
|
}
|
|
6152
6398
|
function emit3(payload, fmt) {
|
|
6153
|
-
process.stdout.write(
|
|
6399
|
+
process.stdout.write(formatObject16(payload, { format: fmt }) + "\n");
|
|
6154
6400
|
}
|
|
6155
6401
|
|
|
6156
6402
|
// src/commands/skills.ts
|
|
@@ -6174,18 +6420,18 @@ import {
|
|
|
6174
6420
|
resolveAllSkillsInstallOrder,
|
|
6175
6421
|
matchSkills,
|
|
6176
6422
|
filterByStage,
|
|
6177
|
-
formatObject as
|
|
6423
|
+
formatObject as formatObject19,
|
|
6178
6424
|
fromAxiosError as fromAxiosError17,
|
|
6179
6425
|
loadGlobalConfig as loadGlobalConfig6,
|
|
6180
6426
|
discoverProjectEnv as discoverProjectEnv3,
|
|
6181
6427
|
resolveEnvContext as resolveEnvContext5,
|
|
6182
6428
|
printResolvedEnvironment as printResolvedEnvironment4,
|
|
6183
|
-
CliError as
|
|
6184
|
-
CliErrorCode as
|
|
6429
|
+
CliError as CliError21,
|
|
6430
|
+
CliErrorCode as CliErrorCode22
|
|
6185
6431
|
} from "@hcmai/sdk";
|
|
6186
6432
|
|
|
6187
6433
|
// src/commands/skills-catalog.ts
|
|
6188
|
-
import { flattenSkills, CliError as
|
|
6434
|
+
import { flattenSkills, CliError as CliError18, CliErrorCode as CliErrorCode19 } from "@hcmai/sdk";
|
|
6189
6435
|
var CLI_CATEGORY_KEY = "cli-operations";
|
|
6190
6436
|
var CLI_CATEGORY_NAME = "CLI \u64CD\u4F5C";
|
|
6191
6437
|
function chironEntry(skill) {
|
|
@@ -6230,8 +6476,8 @@ var SOURCE_FILTERS = ["cli", "chiron", "all"];
|
|
|
6230
6476
|
function parseSourceFilter(raw) {
|
|
6231
6477
|
if (raw === void 0) return "all";
|
|
6232
6478
|
if (SOURCE_FILTERS.includes(raw)) return raw;
|
|
6233
|
-
throw new
|
|
6234
|
-
code:
|
|
6479
|
+
throw new CliError18({
|
|
6480
|
+
code: CliErrorCode19.INVALID_ARGUMENT,
|
|
6235
6481
|
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`
|
|
6236
6482
|
});
|
|
6237
6483
|
}
|
|
@@ -6383,11 +6629,11 @@ import { execFileSync } from "child_process";
|
|
|
6383
6629
|
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync as readFileSync4, rmSync, statSync as statSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
6384
6630
|
import os2 from "os";
|
|
6385
6631
|
import path4 from "path";
|
|
6386
|
-
import { CASES_REPO_SLUG, CASES_REPO_URL, CNB_ORIGIN, CliError as
|
|
6632
|
+
import { CASES_REPO_SLUG, CASES_REPO_URL, CNB_ORIGIN, CliError as CliError19, CliErrorCode as CliErrorCode20, formatObject as formatObject17 } from "@hcmai/sdk";
|
|
6387
6633
|
var casesCacheDir = () => process.env.HCM_CASES_CACHE?.trim() || path4.join(os2.homedir(), ".cache", "hcm", "chiron-cases");
|
|
6388
6634
|
var INDEX_CACHE = () => path4.join(casesCacheDir(), "index.json");
|
|
6389
6635
|
var INDEX_TTL_MS = 60 * 60 * 1e3;
|
|
6390
|
-
var fail5 = (message, nextStep) => new
|
|
6636
|
+
var fail5 = (message, nextStep) => new CliError19({ code: CliErrorCode20.INVALID_ARGUMENT, message, context: { nextStep } });
|
|
6391
6637
|
var run = (cmd, args, opts = {}) => execFileSync(cmd, args, { encoding: "utf8", maxBuffer: 1 << 26, ...opts });
|
|
6392
6638
|
function parseCnbEnvelope(raw, what) {
|
|
6393
6639
|
const trimmed = raw.trim();
|
|
@@ -6482,7 +6728,7 @@ function matchTag(c, fp) {
|
|
|
6482
6728
|
}
|
|
6483
6729
|
function emit4(args, data, text) {
|
|
6484
6730
|
if (args.output === "json" || args.output === "yaml") {
|
|
6485
|
-
process.stdout.write(
|
|
6731
|
+
process.stdout.write(formatObject17(data, { format: args.output }) + "\n");
|
|
6486
6732
|
} else {
|
|
6487
6733
|
process.stdout.write(text() + "\n");
|
|
6488
6734
|
}
|
|
@@ -6756,14 +7002,14 @@ async function inspectJira() {
|
|
|
6756
7002
|
// src/commands/skills-bundled.ts
|
|
6757
7003
|
import { promises as fsp } from "fs";
|
|
6758
7004
|
import * as path7 from "path";
|
|
6759
|
-
import { CliError as
|
|
7005
|
+
import { CliError as CliError20, CliErrorCode as CliErrorCode21, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
|
|
6760
7006
|
|
|
6761
7007
|
// src/commands/skills-manifest.ts
|
|
6762
7008
|
import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync4, existsSync as existsSync2 } from "fs";
|
|
6763
7009
|
import { createHash as createHash3 } from "crypto";
|
|
6764
7010
|
import * as path6 from "path";
|
|
6765
7011
|
import { fileURLToPath } from "url";
|
|
6766
|
-
import { formatObject as
|
|
7012
|
+
import { formatObject as formatObject18, parseSkillFrontmatter } from "@hcmai/sdk";
|
|
6767
7013
|
function collectCommandSurface(root) {
|
|
6768
7014
|
const out = [];
|
|
6769
7015
|
const walk = (cmd, prefix) => {
|
|
@@ -6839,7 +7085,7 @@ function buildManifest(root, skillsDir = bundledSkillsDir()) {
|
|
|
6839
7085
|
}
|
|
6840
7086
|
function skillsManifestCommand(root, args) {
|
|
6841
7087
|
const manifest2 = buildManifest(root);
|
|
6842
|
-
process.stdout.write(
|
|
7088
|
+
process.stdout.write(formatObject18(manifest2, { format: args.output ?? "json" }) + "\n");
|
|
6843
7089
|
}
|
|
6844
7090
|
function str(v) {
|
|
6845
7091
|
return typeof v === "string" && v ? v : void 0;
|
|
@@ -6853,8 +7099,8 @@ function listBundledSkills(dir = bundledSkillsDir()) {
|
|
|
6853
7099
|
return collectBundledSkills(dir);
|
|
6854
7100
|
}
|
|
6855
7101
|
function unreachable(id, detail) {
|
|
6856
|
-
return new
|
|
6857
|
-
code:
|
|
7102
|
+
return new CliError20({
|
|
7103
|
+
code: CliErrorCode21.SKILL_SOURCE_UNREACHABLE,
|
|
6858
7104
|
message: `\u88C5\u5728\u8FD9\u4EFD CLI \u91CC\u7684\u6280\u80FD\u8D44\u6E90\u8BFB\u4E0D\u5230\uFF08${detail}\uFF09\uFF0C\u91CD\u88C5 @hcmai/cli\u3002
|
|
6859
7105
|
\u6280\u80FD id\uFF1A${id}\uFF1B\u627E\u7684\u4F4D\u7F6E\uFF1A${bundledSkillsDir()}`
|
|
6860
7106
|
});
|
|
@@ -6911,8 +7157,8 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
|
|
|
6911
7157
|
const visit = async (id) => {
|
|
6912
7158
|
if (state.get(id) === "done") return;
|
|
6913
7159
|
if (state.get(id) === "visiting") {
|
|
6914
|
-
throw new
|
|
6915
|
-
code:
|
|
7160
|
+
throw new CliError20({
|
|
7161
|
+
code: CliErrorCode21.INVALID_ARGUMENT,
|
|
6916
7162
|
message: `\u81EA\u5E26\u6280\u80FD\u4F9D\u8D56\u6210\u73AF\uFF1A${[...stack, id].join(" \u2192 ")}`
|
|
6917
7163
|
});
|
|
6918
7164
|
}
|
|
@@ -6969,7 +7215,7 @@ async function resolveEndpoint(args) {
|
|
|
6969
7215
|
const env2 = resolved.config;
|
|
6970
7216
|
if (env2?.endpoint) return env2.endpoint.replace(/\/+$/, "");
|
|
6971
7217
|
} catch (e) {
|
|
6972
|
-
if (e?.code !==
|
|
7218
|
+
if (e?.code !== CliErrorCode22.ENV_NOT_FOUND) throw e;
|
|
6973
7219
|
const project = await discoverProjectEnv3();
|
|
6974
7220
|
const name = args.env ?? project?.config.default;
|
|
6975
7221
|
const fromProject = name ? project?.config.environments[name] : void 0;
|
|
@@ -6982,8 +7228,8 @@ async function resolveEndpoint(args) {
|
|
|
6982
7228
|
}
|
|
6983
7229
|
throw e;
|
|
6984
7230
|
}
|
|
6985
|
-
throw new
|
|
6986
|
-
code:
|
|
7231
|
+
throw new CliError21({
|
|
7232
|
+
code: CliErrorCode22.MISSING_FLAG,
|
|
6987
7233
|
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"
|
|
6988
7234
|
});
|
|
6989
7235
|
}
|
|
@@ -7000,8 +7246,8 @@ function decideTrackedEndpoint(options) {
|
|
|
7000
7246
|
}
|
|
7001
7247
|
if (!recorded) {
|
|
7002
7248
|
if (!current) {
|
|
7003
|
-
throw new
|
|
7004
|
-
code:
|
|
7249
|
+
throw new CliError21({
|
|
7250
|
+
code: CliErrorCode22.MISSING_FLAG,
|
|
7005
7251
|
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"
|
|
7006
7252
|
});
|
|
7007
7253
|
}
|
|
@@ -7083,8 +7329,8 @@ async function skillsListCommand(keyword, args, cwd = process.cwd()) {
|
|
|
7083
7329
|
const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
|
|
7084
7330
|
const conflicts = detectIdConflicts(catalog);
|
|
7085
7331
|
if (conflicts.ids.length > 0) {
|
|
7086
|
-
throw new
|
|
7087
|
-
code:
|
|
7332
|
+
throw new CliError21({
|
|
7333
|
+
code: CliErrorCode22.SKILL_ID_CONFLICT,
|
|
7088
7334
|
message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
|
|
7089
7335
|
});
|
|
7090
7336
|
}
|
|
@@ -7115,7 +7361,7 @@ async function skillsListCommand(keyword, args, cwd = process.cwd()) {
|
|
|
7115
7361
|
}
|
|
7116
7362
|
if (fmt === "json" || fmt === "yaml") {
|
|
7117
7363
|
process.stdout.write(
|
|
7118
|
-
|
|
7364
|
+
formatObject19(
|
|
7119
7365
|
{
|
|
7120
7366
|
...manifest2 ?? {},
|
|
7121
7367
|
categories: cats,
|
|
@@ -7204,7 +7450,7 @@ async function listInstalledSkills(keyword, args, cwd = process.cwd()) {
|
|
|
7204
7450
|
const legacy = await detectLegacyFlatLayout(layout);
|
|
7205
7451
|
const legacyState = legacy ? await readSkillsState(legacy) : void 0;
|
|
7206
7452
|
if (fmt === "json" || fmt === "yaml") {
|
|
7207
|
-
process.stdout.write(
|
|
7453
|
+
process.stdout.write(formatObject19({
|
|
7208
7454
|
baseDir: layout.baseDir,
|
|
7209
7455
|
target: layout.target,
|
|
7210
7456
|
all: false,
|
|
@@ -7263,7 +7509,7 @@ async function listInstalledSkills(keyword, args, cwd = process.cwd()) {
|
|
|
7263
7509
|
const shown = sourceFilter === "all" ? byKeyword : byKeyword.filter((row) => row.sourceKind === sourceFilter);
|
|
7264
7510
|
const groupOf = (kind) => kind === "cli" ? "CLI \u81EA\u5E26" : kind === "local" ? "\u672C\u9879\u76EE\u81EA\u5DF1\u7684\uFF08hcm-skills/local/\uFF09" : "\u777F\u620E\u6280\u80FD\u5E93";
|
|
7265
7511
|
if (fmt === "json" || fmt === "yaml") {
|
|
7266
|
-
process.stdout.write(
|
|
7512
|
+
process.stdout.write(formatObject19({
|
|
7267
7513
|
baseDir: layout.baseDir,
|
|
7268
7514
|
target: layout.target,
|
|
7269
7515
|
endpoint: state?.endpoint,
|
|
@@ -7374,7 +7620,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
7374
7620
|
const tracked = decideTrackedEndpoint({
|
|
7375
7621
|
explicit: Boolean(args.endpoint || args.env),
|
|
7376
7622
|
current: await resolveEndpoint(args).catch((error) => {
|
|
7377
|
-
if (error instanceof
|
|
7623
|
+
if (error instanceof CliError21 && error.code === CliErrorCode22.NO_ACTIVE_ENV) return void 0;
|
|
7378
7624
|
throw error;
|
|
7379
7625
|
}),
|
|
7380
7626
|
recorded: (await readSkillsState(layout.baseDir))?.endpoint
|
|
@@ -7388,8 +7634,8 @@ async function skillsInstallCommand(id, args) {
|
|
|
7388
7634
|
const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
|
|
7389
7635
|
const conflicts = detectIdConflicts(catalog);
|
|
7390
7636
|
if (conflicts.ids.length > 0) {
|
|
7391
|
-
throw new
|
|
7392
|
-
code:
|
|
7637
|
+
throw new CliError21({
|
|
7638
|
+
code: CliErrorCode22.SKILL_ID_CONFLICT,
|
|
7393
7639
|
message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
|
|
7394
7640
|
});
|
|
7395
7641
|
}
|
|
@@ -7470,7 +7716,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
7470
7716
|
const legacyState = await readSkillsState(legacyForCheck);
|
|
7471
7717
|
const count = Object.keys(legacyState?.skills ?? {}).length;
|
|
7472
7718
|
if (fmtCheck === "json" || fmtCheck === "yaml") {
|
|
7473
|
-
process.stdout.write(
|
|
7719
|
+
process.stdout.write(formatObject19({
|
|
7474
7720
|
dryRun: true,
|
|
7475
7721
|
legacyFlatLayout: { dir: legacyForCheck, skills: count },
|
|
7476
7722
|
wouldMigrate: true,
|
|
@@ -7488,7 +7734,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
7488
7734
|
}
|
|
7489
7735
|
const would = documents.map((d) => d.id).sort();
|
|
7490
7736
|
if (fmtCheck === "json" || fmtCheck === "yaml") {
|
|
7491
|
-
process.stdout.write(
|
|
7737
|
+
process.stdout.write(formatObject19({
|
|
7492
7738
|
dryRun: true,
|
|
7493
7739
|
baseDir: layout.baseDir,
|
|
7494
7740
|
target: layout.target,
|
|
@@ -7523,7 +7769,7 @@ async function skillsInstallCommand(id, args) {
|
|
|
7523
7769
|
const agents = agentIndexes[0]?.status;
|
|
7524
7770
|
const fmt = args.output ?? "table";
|
|
7525
7771
|
if (fmt === "json" || fmt === "yaml") {
|
|
7526
|
-
process.stdout.write(
|
|
7772
|
+
process.stdout.write(formatObject19({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
|
|
7527
7773
|
} else {
|
|
7528
7774
|
const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path8.join(result.baseDir, id, "SKILL.md")}`;
|
|
7529
7775
|
process.stdout.write(`${headline}
|
|
@@ -7668,8 +7914,8 @@ async function resolveSkillPath(layout, id) {
|
|
|
7668
7914
|
...layout.localDir ? [`${layout.localDir}/${id}/SKILL.md`] : [],
|
|
7669
7915
|
`${layout.baseDir}/${id}/SKILL.md`
|
|
7670
7916
|
];
|
|
7671
|
-
throw new
|
|
7672
|
-
code:
|
|
7917
|
+
throw new CliError21({
|
|
7918
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
7673
7919
|
message: `\u8FD9\u4E2A\u9879\u76EE\u91CC\u6CA1\u6709\u6280\u80FD ${id}\u3002\u627E\u8FC7\uFF1A
|
|
7674
7920
|
${looked.join("\n ")}
|
|
7675
7921
|
\u770B\u6709\u54EA\u4E9B\uFF1Ahcm skills list --installed\uFF1B\u6CA1\u88C5\u5C31\u5148 hcm chiron skills sync\u3002`
|
|
@@ -7681,7 +7927,7 @@ async function skillsPathCommand(id, args) {
|
|
|
7681
7927
|
const resolved = await resolveSkillPath(layout, id);
|
|
7682
7928
|
const fmt = args.output ?? "table";
|
|
7683
7929
|
if (fmt === "json" || fmt === "yaml") {
|
|
7684
|
-
process.stdout.write(
|
|
7930
|
+
process.stdout.write(formatObject19(resolved, { format: fmt }) + "\n");
|
|
7685
7931
|
process.exitCode = 0;
|
|
7686
7932
|
return;
|
|
7687
7933
|
}
|
|
@@ -8102,15 +8348,15 @@ function parsePruneMax(raw) {
|
|
|
8102
8348
|
const text = typeof raw === "number" ? void 0 : raw.trim();
|
|
8103
8349
|
const n = text === void 0 ? raw : text === "" ? Number.NaN : Number(text);
|
|
8104
8350
|
if (!Number.isInteger(n) || n < 0) {
|
|
8105
|
-
throw new
|
|
8106
|
-
code:
|
|
8351
|
+
throw new CliError21({
|
|
8352
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
8107
8353
|
message: `--prune-max \u8981\u4E00\u4E2A\u975E\u8D1F\u6574\u6570\uFF0C\u6536\u5230 ${JSON.stringify(raw)}\u30020 = \u8FD9\u4E00\u8D9F\u4E00\u4EFD\u90FD\u522B\u6E05\uFF1B\u4E0D\u7ED9\u8FD9\u4E2A\u53C2\u6570\u65F6\u4E0A\u9650\u662F\u300C${PRUNE_DEFAULT_MAX} \u4E0E\u5728\u518C\u4EFD\u6570\u4E00\u534A\u53D6\u5C0F\u300D\u3002`
|
|
8108
8354
|
});
|
|
8109
8355
|
}
|
|
8110
8356
|
return n;
|
|
8111
8357
|
}
|
|
8112
8358
|
function invalid(message) {
|
|
8113
|
-
return new
|
|
8359
|
+
return new CliError21({ code: CliErrorCode22.INVALID_ARGUMENT, message });
|
|
8114
8360
|
}
|
|
8115
8361
|
var PRUNE_DEFAULT_MAX = 5;
|
|
8116
8362
|
var PRUNE_MAX_SHARE = 0.5;
|
|
@@ -8338,8 +8584,8 @@ async function skillsUpdateCommand(args) {
|
|
|
8338
8584
|
const layout = await resolveInstallLayout(args);
|
|
8339
8585
|
const state = await readSkillsState(layout.baseDir);
|
|
8340
8586
|
if (!state || Object.keys(state.skills).length === 0) {
|
|
8341
|
-
throw new
|
|
8342
|
-
code:
|
|
8587
|
+
throw new CliError21({
|
|
8588
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
8343
8589
|
message: `${path8.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\u8DD1 \`hcm chiron skills sync\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u540C\u6B65\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
|
|
8344
8590
|
});
|
|
8345
8591
|
}
|
|
@@ -8347,7 +8593,7 @@ async function skillsUpdateCommand(args) {
|
|
|
8347
8593
|
const endpoint = decideTrackedEndpoint({
|
|
8348
8594
|
explicit: Boolean(args.endpoint || args.env),
|
|
8349
8595
|
current: await resolveEndpoint(args).catch((error) => {
|
|
8350
|
-
if (error instanceof
|
|
8596
|
+
if (error instanceof CliError21 && error.code === CliErrorCode22.NO_ACTIVE_ENV) return void 0;
|
|
8351
8597
|
throw error;
|
|
8352
8598
|
}),
|
|
8353
8599
|
recorded: state.endpoint
|
|
@@ -8395,7 +8641,7 @@ async function skillsUpdateCommand(args) {
|
|
|
8395
8641
|
const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
|
|
8396
8642
|
const fmt = args.output ?? "table";
|
|
8397
8643
|
if (fmt === "json" || fmt === "yaml") {
|
|
8398
|
-
process.stdout.write(
|
|
8644
|
+
process.stdout.write(formatObject19({
|
|
8399
8645
|
endpoint,
|
|
8400
8646
|
baseDir: layout.baseDir,
|
|
8401
8647
|
target: layout.target,
|
|
@@ -8621,26 +8867,94 @@ async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
|
|
|
8621
8867
|
// src/commands/tenant.ts
|
|
8622
8868
|
import {
|
|
8623
8869
|
bootstrapTenant,
|
|
8870
|
+
resetTenant,
|
|
8871
|
+
HcmClient as HcmClient20,
|
|
8872
|
+
readSessionPrincipal as readSessionPrincipal2,
|
|
8624
8873
|
discoverProjectEnv as discoverProjectEnv4,
|
|
8625
|
-
assertDangerWrite as
|
|
8874
|
+
assertDangerWrite as assertDangerWrite4,
|
|
8626
8875
|
normalizeOrigin as normalizeOrigin4,
|
|
8627
8876
|
createHttpClient as createHttpClient3,
|
|
8628
|
-
formatObject as
|
|
8877
|
+
formatObject as formatObject20,
|
|
8629
8878
|
fromAxiosError as fromAxiosError18,
|
|
8630
8879
|
loadGlobalConfig as loadGlobalConfig7,
|
|
8631
8880
|
resolveEnvContext as resolveEnvContext6,
|
|
8632
8881
|
printResolvedEnvironment as printResolvedEnvironment5,
|
|
8633
|
-
CliError as
|
|
8634
|
-
CliErrorCode as
|
|
8882
|
+
CliError as CliError22,
|
|
8883
|
+
CliErrorCode as CliErrorCode23
|
|
8635
8884
|
} from "@hcmai/sdk";
|
|
8636
8885
|
init_exit();
|
|
8886
|
+
init_auth_guard();
|
|
8887
|
+
async function tenantResetCommand(args) {
|
|
8888
|
+
let attempted = false;
|
|
8889
|
+
try {
|
|
8890
|
+
const fmt = args.output ?? "json";
|
|
8891
|
+
if (!["table", "json", "yaml"].includes(fmt)) throw new CliError22({
|
|
8892
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
8893
|
+
message: "--output \u53D6\u503C table | json | yaml"
|
|
8894
|
+
});
|
|
8895
|
+
const ctx = await getActiveAuthContextFromCli(args);
|
|
8896
|
+
if (ctx.impersonation) throw new CliError22({
|
|
8897
|
+
code: CliErrorCode23.SCOPE_FORBIDDEN,
|
|
8898
|
+
message: "\u79DF\u6237\u91CD\u7F6E\u4E0D\u63A5\u53D7\u4EE3\u7406\u4F1A\u8BDD\uFF0C\u8BF7\u7528\u5185\u7F6E admin \u7684\u76F4\u63A5\u767B\u5F55\u8EAB\u4EFD\u3002"
|
|
8899
|
+
});
|
|
8900
|
+
const { endpoint, tenantId, env: env2 } = ctx;
|
|
8901
|
+
const safety = ctx.environmentSafety ? { ...ctx.environmentSafety } : void 0;
|
|
8902
|
+
assertDangerWrite4(safety, "\u91CD\u7F6E\u79DF\u6237 PostgreSQL \u6570\u636E");
|
|
8903
|
+
const accessToken = await HcmClient20.fromAuthContext(ctx).getAccessToken();
|
|
8904
|
+
if (!accessToken) throw new CliError22({ code: CliErrorCode23.AUTH_FAILED, message: "\u5F53\u524D\u8EAB\u4EFD\u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u51ED\u636E\uFF0C\u672A\u53D1\u9001\u91CD\u7F6E\u3002" });
|
|
8905
|
+
const client3 = new HcmClient20({ endpoint, tenantId, accessToken, profile: env2, environmentSafety: safety });
|
|
8906
|
+
client3.raw().defaults.maxRedirects = 0;
|
|
8907
|
+
client3.raw().defaults.__skipRetry = true;
|
|
8908
|
+
const principal = await readSessionPrincipal2(client3.raw());
|
|
8909
|
+
if (principal.tenantId !== tenantId || principal.username !== "admin" || !principal.roles?.includes("admin.system") || principal.impersonated || principal.actSub != null) {
|
|
8910
|
+
throw new CliError22({
|
|
8911
|
+
code: CliErrorCode23.SCOPE_FORBIDDEN,
|
|
8912
|
+
message: `\u5B9E\u9645\u8EAB\u4EFD ${principal.username} / \u79DF\u6237 ${principal.tenantId} \u4E0D\u662F\u76EE\u6807 ${tenantId} \u7684\u76F4\u63A5\u5185\u7F6E\u7BA1\u7406\u5458\uFF0C\u672A\u53D1\u9001\u91CD\u7F6E\u3002`,
|
|
8913
|
+
context: { nextStep: `hcm login --env ${env2} \u767B\u5F55\u76EE\u6807\u79DF\u6237\u7684\u5185\u7F6E admin \u540E\u91CD\u8BD5\u3002` }
|
|
8914
|
+
});
|
|
8915
|
+
}
|
|
8916
|
+
process.stderr.write(`\u2192 \u91CD\u7F6E\u76EE\u6807 ${endpoint} \xB7 \u73AF\u5883 ${env2} \xB7 \u79DF\u6237 ${tenantId} \xB7 \u7528\u6237 ${principal.username}
|
|
8917
|
+
\u5C06\u4E0D\u53EF\u9006\u5730\u5220\u9664 PostgreSQL \u4E1A\u52A1\u6570\u636E\u5E76\u6062\u590D\u51FA\u5382\u57FA\u7EBF\uFF1BMongo\u3001\u6587\u6863\u5BF9\u8C61\u4E0E\u5916\u90E8\u5411\u91CF\u4E0D\u5904\u7406\u3001\u4E0D\u6838\u9A8C\u3002
|
|
8918
|
+
`);
|
|
8919
|
+
if (!args.yes) {
|
|
8920
|
+
if (!process.stdin.isTTY) throw new CliError22({
|
|
8921
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
8922
|
+
message: "\u975E\u4EA4\u4E92\u8F93\u5165\u672A\u786E\u8BA4\u79DF\u6237\u91CD\u7F6E\uFF0C\u672A\u53D1\u9001\u91CD\u7F6E\u3002",
|
|
8923
|
+
context: { nextStep: "\u6838\u5BF9\u4E0A\u8FF0\u76EE\u6807\u4E0E\u5F71\u54CD\u540E\u663E\u5F0F\u52A0 --yes\uFF1B\u5371\u9669\u73AF\u5883\u8FD8\u9700\u8981 --allow-danger\u3002" }
|
|
8924
|
+
});
|
|
8925
|
+
const answer = await promptText("\u786E\u8BA4\u91CD\u7F6E\u8FD9\u4E2A\u79DF\u6237\uFF1F\u8F93\u5165 yes \u7EE7\u7EED\uFF1A", process.stderr);
|
|
8926
|
+
if (!/^y(es)?$/i.test(answer)) throw new CliError22({ code: CliErrorCode23.INVALID_ARGUMENT, message: "\u5DF2\u53D6\u6D88\uFF0C\u672A\u53D1\u9001\u91CD\u7F6E\u3002" });
|
|
8927
|
+
}
|
|
8928
|
+
attempted = true;
|
|
8929
|
+
const receipt = await resetTenant(client3.raw(), tenantId);
|
|
8930
|
+
if (fmt === "table") process.stdout.write(
|
|
8931
|
+
`\u79DF\u6237 ${receipt.tenantId} \xB7 \u6D41\u6C34 ${receipt.runId}
|
|
8932
|
+
\u5220\u9664 ${receipt.deletedRows} \u884C / \u6D89\u53CA ${receipt.touchedTables} \u8868 / \u91CD\u5EFA ${receipt.restoredRows} \u884C
|
|
8933
|
+
PostgreSQL \u6838\u9A8C=${receipt.pgVerified}\uFF1B\u6574\u4F53\u6838\u9A8C=${receipt.overallVerified}\uFF1B\u8BB0\u8D26=${receipt.journalReconciledMarked}
|
|
8934
|
+
\u975E PG ${receipt.nonPgSurface.status}\uFF1A${receipt.nonPgSurface.reason}
|
|
8935
|
+
\u4E0B\u4E00\u6B65\uFF1A${receipt.nonPgSurface.nextStep}
|
|
8936
|
+
`
|
|
8937
|
+
);
|
|
8938
|
+
process.stdout.write(formatObject20(receipt, { format: fmt }) + "\n");
|
|
8939
|
+
const quote = (value) => "'" + value.replace(/'/g, "'\\''") + "'";
|
|
8940
|
+
process.stderr.write(`\u91CD\u7F6E\u5DF2\u6E05\u7406\u5F53\u524D\u4F1A\u8BDD\uFF1B\u8BF7 hcm login --env ${quote(env2)} --endpoint ${quote(endpoint)} --tenant ${quote(tenantId)} \u91CD\u65B0\u767B\u5F55\uFF0C\u518D\u67E5\u8BE2\u6216\u88C5\u5305\u3002
|
|
8941
|
+
`);
|
|
8942
|
+
if (!receipt.journalReconciledMarked) process.stderr.write("\u91CD\u7F6E\u56DE\u6267\u8BB0\u8D26\u672A\u786E\u8BA4\uFF1B\u8BF7\u6309 runId \u6838\u67E5\u670D\u52A1\u7AEF\u6D41\u6C34\uFF0C\u52FF\u56E0\u8BB0\u8D26\u72B6\u6001\u91CD\u8DD1\u91CD\u7F6E\u3002\n");
|
|
8943
|
+
if (!receipt.pgVerified) process.stderr.write("PostgreSQL \u57FA\u7EBF\u672A\u6838\u9A8C\uFF0C\u4E0D\u80FD\u5BA3\u79F0\u91CD\u7F6E\u5B8C\u6210\uFF1B\u8BF7\u6309 runId \u6838\u67E5\u3002\n");
|
|
8944
|
+
process.exitCode = receipt.pgVerified ? 0 : 4;
|
|
8945
|
+
} catch (error) {
|
|
8946
|
+
if (attempted) process.stderr.write("TENANT_RESET_RESULT_UNKNOWN\uFF1A\u672C\u6B21\u5DF2\u5C1D\u8BD5\u4E00\u6B21\u91CD\u7F6E\uFF0C\u7ED3\u679C\u672A\u786E\u8BA4\uFF1B\u672A\u81EA\u52A8\u91CD\u8BD5\u3002\u4E0D\u8981\u76F2\u76EE\u91CD\u8DD1\uFF0C\u8BF7\u6838\u67E5\u670D\u52A1\u7AEF\u6D41\u6C34\u4E0E\u5F53\u524D\u79DF\u6237\u72B6\u6001\u3002\n");
|
|
8947
|
+
const e = error;
|
|
8948
|
+
exitWithError(e?.isAxiosError ? fromAxiosError18(error, args.env) : error);
|
|
8949
|
+
}
|
|
8950
|
+
}
|
|
8637
8951
|
async function resolveBootstrapKey(args, stdinTaken) {
|
|
8638
8952
|
const fromEnv = process.env.HCM_BOOTSTRAP_KEY;
|
|
8639
8953
|
if (fromEnv) return fromEnv;
|
|
8640
8954
|
if (args.bootstrapKeyStdin) {
|
|
8641
8955
|
if (stdinTaken) {
|
|
8642
|
-
throw new
|
|
8643
|
-
code:
|
|
8956
|
+
throw new CliError22({
|
|
8957
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
8644
8958
|
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"
|
|
8645
8959
|
});
|
|
8646
8960
|
}
|
|
@@ -8671,8 +8985,8 @@ async function resolveEndpoint2(args) {
|
|
|
8671
8985
|
printResolvedEnvironment5(resolved);
|
|
8672
8986
|
const env2 = resolved.config;
|
|
8673
8987
|
if (!env2?.endpoint) {
|
|
8674
|
-
throw new
|
|
8675
|
-
code:
|
|
8988
|
+
throw new CliError22({
|
|
8989
|
+
code: CliErrorCode23.MISSING_FLAG,
|
|
8676
8990
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
|
|
8677
8991
|
});
|
|
8678
8992
|
}
|
|
@@ -8681,15 +8995,15 @@ async function resolveEndpoint2(args) {
|
|
|
8681
8995
|
async function tenantBootstrapCommand(args) {
|
|
8682
8996
|
try {
|
|
8683
8997
|
if (!args.tenantId || !args.adminUsername) {
|
|
8684
|
-
throw new
|
|
8685
|
-
code:
|
|
8998
|
+
throw new CliError22({
|
|
8999
|
+
code: CliErrorCode23.MISSING_FLAG,
|
|
8686
9000
|
message: "--tenant-id \u4E0E --admin-username \u5FC5\u586B"
|
|
8687
9001
|
});
|
|
8688
9002
|
}
|
|
8689
9003
|
const endpoint = await resolveEndpoint2(args);
|
|
8690
9004
|
const project = await discoverProjectEnv4();
|
|
8691
9005
|
const protectedNames = project ? Object.entries(project.config.environments).filter(([, candidate]) => candidate.danger && candidate.endpoint === normalizeOrigin4(endpoint)).map(([name]) => name) : [];
|
|
8692
|
-
|
|
9006
|
+
assertDangerWrite4({ name: protectedNames.join(", "), danger: protectedNames.length > 0, allowDanger: args.allowDanger }, "\u5F00\u901A\u79DF\u6237");
|
|
8693
9007
|
if (args.endpoint) process.stderr.write(`\u2192 ${endpoint} \xB7 \u79DF\u6237 ${args.tenantId} \xB7 \u8EAB\u4EFD bootstrap key\uFF08\u6765\u81EA --endpoint\uFF09
|
|
8694
9008
|
`);
|
|
8695
9009
|
const { pwd, stdinTaken } = await resolveAdminPassword(args);
|
|
@@ -8723,7 +9037,7 @@ async function tenantBootstrapCommand(args) {
|
|
|
8723
9037
|
`
|
|
8724
9038
|
);
|
|
8725
9039
|
}
|
|
8726
|
-
process.stdout.write(
|
|
9040
|
+
process.stdout.write(formatObject20(result, { format: fmt }) + "\n");
|
|
8727
9041
|
process.exitCode = 0;
|
|
8728
9042
|
return;
|
|
8729
9043
|
} catch (e) {
|
|
@@ -8743,8 +9057,8 @@ import { promises as fsp3 } from "fs";
|
|
|
8743
9057
|
import os4 from "os";
|
|
8744
9058
|
import nodePath from "path";
|
|
8745
9059
|
import {
|
|
8746
|
-
HcmClient as
|
|
8747
|
-
formatObject as
|
|
9060
|
+
HcmClient as HcmClient21,
|
|
9061
|
+
formatObject as formatObject21,
|
|
8748
9062
|
fromAxiosError as fromAxiosError19,
|
|
8749
9063
|
listTenantMeta,
|
|
8750
9064
|
getTenantMeta,
|
|
@@ -8755,14 +9069,14 @@ import {
|
|
|
8755
9069
|
formatMetaIssues,
|
|
8756
9070
|
explainJacksonError,
|
|
8757
9071
|
META_SCHEMA_SOURCE_COMMIT,
|
|
8758
|
-
CliError as
|
|
8759
|
-
CliErrorCode as
|
|
9072
|
+
CliError as CliError23,
|
|
9073
|
+
CliErrorCode as CliErrorCode24
|
|
8760
9074
|
} from "@hcmai/sdk";
|
|
8761
9075
|
init_exit();
|
|
8762
9076
|
init_impersonation_lifecycle();
|
|
8763
9077
|
init_auth_guard();
|
|
8764
9078
|
async function client2(args) {
|
|
8765
|
-
return
|
|
9079
|
+
return HcmClient21.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
8766
9080
|
}
|
|
8767
9081
|
function formatMetaForbiddenMessage(mode = "write") {
|
|
8768
9082
|
if (mode === "read") {
|
|
@@ -8793,7 +9107,7 @@ async function metaListCommand(args) {
|
|
|
8793
9107
|
const fmt = args.output ?? "json";
|
|
8794
9108
|
if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
|
|
8795
9109
|
`);
|
|
8796
|
-
process.stdout.write(
|
|
9110
|
+
process.stdout.write(formatObject21(items, { format: fmt }) + "\n");
|
|
8797
9111
|
process.exitCode = 0;
|
|
8798
9112
|
return;
|
|
8799
9113
|
} catch (e) {
|
|
@@ -8881,8 +9195,8 @@ async function verifyAfterWrite(c, path19) {
|
|
|
8881
9195
|
async function metaSetCommand(path19, args) {
|
|
8882
9196
|
try {
|
|
8883
9197
|
if (!args.file) {
|
|
8884
|
-
throw new
|
|
8885
|
-
code:
|
|
9198
|
+
throw new CliError23({
|
|
9199
|
+
code: CliErrorCode24.MISSING_FLAG,
|
|
8886
9200
|
message: "--file <path> \u5FC5\u586B\uFF08\u4ECE\u6587\u4EF6\u8BFB\u53D6 meta \u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
|
|
8887
9201
|
});
|
|
8888
9202
|
}
|
|
@@ -8914,7 +9228,7 @@ async function metaSetCommand(path19, args) {
|
|
|
8914
9228
|
const dryFmt = args.output;
|
|
8915
9229
|
if (dryFmt === "json" || dryFmt === "yaml") {
|
|
8916
9230
|
process.stdout.write(
|
|
8917
|
-
|
|
9231
|
+
formatObject21(
|
|
8918
9232
|
{ dryRun: true, path: path19, bytes: Buffer.byteLength(content), content },
|
|
8919
9233
|
{ format: dryFmt }
|
|
8920
9234
|
) + "\n"
|
|
@@ -8997,7 +9311,7 @@ ${content}
|
|
|
8997
9311
|
process.stdout.write(" \u5DF2\u6E05\u5143\u6570\u636E\u7F13\u5B58\uFF0C\u5E76\u771F\u8BFB\u4E86\u4E00\u904D\uFF1A\u670D\u52A1\u7AEF\u8BFB\u5F97\u52A8 \u2714\n");
|
|
8998
9312
|
}
|
|
8999
9313
|
}
|
|
9000
|
-
process.stdout.write(
|
|
9314
|
+
process.stdout.write(formatObject21(result, { format: fmt }) + "\n");
|
|
9001
9315
|
process.exitCode = 0;
|
|
9002
9316
|
return;
|
|
9003
9317
|
} catch (e) {
|
|
@@ -9019,7 +9333,7 @@ async function metaDeleteCommand(path19, args) {
|
|
|
9019
9333
|
const fmt = args.output ?? "json";
|
|
9020
9334
|
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path19}
|
|
9021
9335
|
`);
|
|
9022
|
-
process.stdout.write(
|
|
9336
|
+
process.stdout.write(formatObject21(result, { format: fmt }) + "\n");
|
|
9023
9337
|
process.exitCode = 0;
|
|
9024
9338
|
return;
|
|
9025
9339
|
} catch (e) {
|
|
@@ -9029,8 +9343,8 @@ async function metaDeleteCommand(path19, args) {
|
|
|
9029
9343
|
async function metaValidateCommand(path19, args) {
|
|
9030
9344
|
try {
|
|
9031
9345
|
if (!args.file) {
|
|
9032
|
-
throw new
|
|
9033
|
-
code:
|
|
9346
|
+
throw new CliError23({
|
|
9347
|
+
code: CliErrorCode24.MISSING_FLAG,
|
|
9034
9348
|
message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
|
|
9035
9349
|
});
|
|
9036
9350
|
}
|
|
@@ -9045,7 +9359,7 @@ async function metaValidateCommand(path19, args) {
|
|
|
9045
9359
|
const fmt = args.output ?? "table";
|
|
9046
9360
|
if (fmt === "json" || fmt === "yaml") {
|
|
9047
9361
|
process.stdout.write(
|
|
9048
|
-
|
|
9362
|
+
formatObject21(
|
|
9049
9363
|
{
|
|
9050
9364
|
path: path19,
|
|
9051
9365
|
kind: result.kind,
|
|
@@ -9086,10 +9400,10 @@ import {
|
|
|
9086
9400
|
createWorkspaceFile,
|
|
9087
9401
|
deleteWorkspaceFile,
|
|
9088
9402
|
formatMiniVerifyReport,
|
|
9089
|
-
formatObject as
|
|
9090
|
-
formatRows as
|
|
9403
|
+
formatObject as formatObject22,
|
|
9404
|
+
formatRows as formatRows6,
|
|
9091
9405
|
getMiniStatus,
|
|
9092
|
-
HcmClient as
|
|
9406
|
+
HcmClient as HcmClient22,
|
|
9093
9407
|
initMiniAppProject,
|
|
9094
9408
|
inferMiniWritableTemplateOptionsFromModel,
|
|
9095
9409
|
listWorkspaceFiles,
|
|
@@ -9146,7 +9460,7 @@ var RAW_WORKSPACE_EXCLUDED_DIRS = /* @__PURE__ */ new Set([
|
|
|
9146
9460
|
var RAW_WORKSPACE_EXCLUDED_FILES = /* @__PURE__ */ new Set([WORKSPACE_CONTEXT_FILE, ".DS_Store"]);
|
|
9147
9461
|
async function workspaceListCommand(args) {
|
|
9148
9462
|
try {
|
|
9149
|
-
const client3 =
|
|
9463
|
+
const client3 = HcmClient22.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
9150
9464
|
const limit = parsePositiveInt3(args.limit, 50, "--limit");
|
|
9151
9465
|
const result = await client3.query("TenantExtensionWorkspace", {
|
|
9152
9466
|
keyword: args.keyword,
|
|
@@ -9179,7 +9493,7 @@ async function workspaceActiveCommand(args) {
|
|
|
9179
9493
|
const ctx = await getActiveAuthContextFromCli(args, {
|
|
9180
9494
|
fallbackEnv: localContext?.profile
|
|
9181
9495
|
});
|
|
9182
|
-
const client3 =
|
|
9496
|
+
const client3 = HcmClient22.fromAuthContext(ctx);
|
|
9183
9497
|
const result = await client3.query("TenantExtensionWorkspace", {
|
|
9184
9498
|
filter: { devModeEnabled: true },
|
|
9185
9499
|
fields: ["workspaceKey", "devModeEnabled"],
|
|
@@ -9237,7 +9551,7 @@ async function workspaceCreateCommand(workspaceKey, args) {
|
|
|
9237
9551
|
`${WORKSPACE_CONTEXT_FILE} already binds workspace '${existing.workspaceKey}'; use --force to rebind`
|
|
9238
9552
|
);
|
|
9239
9553
|
}
|
|
9240
|
-
const client3 =
|
|
9554
|
+
const client3 = HcmClient22.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
9241
9555
|
const normalizedWorkspaceKey = normalizeWorkspaceKey(workspaceKey);
|
|
9242
9556
|
const resp = await client3.raw().post("/api/models/TenantExtensionWorkspace", {
|
|
9243
9557
|
workspaceKey: normalizedWorkspaceKey,
|
|
@@ -9285,7 +9599,7 @@ async function workspacePullCommand(args) {
|
|
|
9285
9599
|
`workspace key is required; pass --workspace <key> or run hcm workspace bind <key> first`
|
|
9286
9600
|
);
|
|
9287
9601
|
}
|
|
9288
|
-
const client3 =
|
|
9602
|
+
const client3 = HcmClient22.fromAuthContext(
|
|
9289
9603
|
await getActiveAuthContextFromCli(args, { fallbackEnv: existing?.profile })
|
|
9290
9604
|
);
|
|
9291
9605
|
const context = buildWorkspaceContext({
|
|
@@ -9439,7 +9753,7 @@ async function workspaceRmCommand(relativePath, args) {
|
|
|
9439
9753
|
if (!stat) {
|
|
9440
9754
|
if (manifestEntry) {
|
|
9441
9755
|
process.stdout.write(
|
|
9442
|
-
|
|
9756
|
+
formatObject22(
|
|
9443
9757
|
{
|
|
9444
9758
|
workspaceKey: context.workspaceKey,
|
|
9445
9759
|
file: normalized,
|
|
@@ -9464,7 +9778,7 @@ async function workspaceRmCommand(relativePath, args) {
|
|
|
9464
9778
|
next: `hcm workspace push --dir ${args.dir ?? "."}`
|
|
9465
9779
|
};
|
|
9466
9780
|
if (args.output === "json" || args.output === "yaml") {
|
|
9467
|
-
process.stdout.write(
|
|
9781
|
+
process.stdout.write(formatObject22(result, { format: args.output }) + "\n");
|
|
9468
9782
|
} else {
|
|
9469
9783
|
process.stdout.write(`workspace file staged for deletion: ${normalized}
|
|
9470
9784
|
`);
|
|
@@ -9511,10 +9825,10 @@ async function workspaceStatusCommand(args) {
|
|
|
9511
9825
|
}
|
|
9512
9826
|
if (args.output === "json" || args.output === "yaml") {
|
|
9513
9827
|
process.stdout.write(
|
|
9514
|
-
|
|
9828
|
+
formatObject22({ rootDir, miniApps: rows2 }, { format: args.output }) + "\n"
|
|
9515
9829
|
);
|
|
9516
9830
|
} else {
|
|
9517
|
-
process.stdout.write(
|
|
9831
|
+
process.stdout.write(formatRows6(rows2, { format: "table" }) + "\n");
|
|
9518
9832
|
}
|
|
9519
9833
|
process.exitCode = 0;
|
|
9520
9834
|
return;
|
|
@@ -9545,7 +9859,7 @@ async function workspacePushCommand(args) {
|
|
|
9545
9859
|
const rootDir = resolveRootDir(args.dir);
|
|
9546
9860
|
const context = await requireWorkspaceContext(rootDir);
|
|
9547
9861
|
const miniApps = await discoverMiniApps(rootDir);
|
|
9548
|
-
const client3 =
|
|
9862
|
+
const client3 = HcmClient22.fromAuthContext(
|
|
9549
9863
|
await getActiveAuthContextFromCli(args, { fallbackEnv: context.profile })
|
|
9550
9864
|
);
|
|
9551
9865
|
const activeWorkspaceKey = args.dryRun ? null : await probeActiveWorkspaceKey(client3);
|
|
@@ -9616,9 +9930,9 @@ async function workspacePreviewCommand(args) {
|
|
|
9616
9930
|
);
|
|
9617
9931
|
}
|
|
9618
9932
|
if (args.output === "json" || args.output === "yaml") {
|
|
9619
|
-
process.stdout.write(
|
|
9933
|
+
process.stdout.write(formatObject22(rows2, { format: args.output }) + "\n");
|
|
9620
9934
|
} else {
|
|
9621
|
-
process.stdout.write(
|
|
9935
|
+
process.stdout.write(formatRows6(rows2, { format: "table" }) + "\n");
|
|
9622
9936
|
}
|
|
9623
9937
|
process.exitCode = 0;
|
|
9624
9938
|
return;
|
|
@@ -10093,7 +10407,7 @@ async function readMiniStatusSafely(app) {
|
|
|
10093
10407
|
async function loadProfileClient(args) {
|
|
10094
10408
|
try {
|
|
10095
10409
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10096
|
-
return
|
|
10410
|
+
return HcmClient22.fromAuthContext(ctx);
|
|
10097
10411
|
} catch (e) {
|
|
10098
10412
|
if (args.env || args.profile) throw e;
|
|
10099
10413
|
return null;
|
|
@@ -10260,10 +10574,10 @@ function optionalText(value) {
|
|
|
10260
10574
|
}
|
|
10261
10575
|
function writeWorkspaceListResult(rows2, format, total) {
|
|
10262
10576
|
if (format !== "table") {
|
|
10263
|
-
process.stdout.write(
|
|
10577
|
+
process.stdout.write(formatObject22({ rows: rows2, total }, { format }) + "\n");
|
|
10264
10578
|
return;
|
|
10265
10579
|
}
|
|
10266
|
-
process.stdout.write(
|
|
10580
|
+
process.stdout.write(formatRows6(toWorkspaceListRows(rows2), { format: "table" }) + "\n");
|
|
10267
10581
|
if (total !== void 0) {
|
|
10268
10582
|
process.stdout.write(`Showing ${rows2.length} of ${total} workspaces.
|
|
10269
10583
|
`);
|
|
@@ -10271,7 +10585,7 @@ function writeWorkspaceListResult(rows2, format, total) {
|
|
|
10271
10585
|
}
|
|
10272
10586
|
function writeWorkspaceActiveResult(view, format) {
|
|
10273
10587
|
if (format !== "table") {
|
|
10274
|
-
process.stdout.write(
|
|
10588
|
+
process.stdout.write(formatObject22(view, { format }) + "\n");
|
|
10275
10589
|
return;
|
|
10276
10590
|
}
|
|
10277
10591
|
const rows2 = [
|
|
@@ -10285,7 +10599,7 @@ function writeWorkspaceActiveResult(view, format) {
|
|
|
10285
10599
|
dir: view.rootDir
|
|
10286
10600
|
}
|
|
10287
10601
|
];
|
|
10288
|
-
process.stdout.write(
|
|
10602
|
+
process.stdout.write(formatRows6(rows2, { format: "table" }) + "\n");
|
|
10289
10603
|
if (view.nextCommand) {
|
|
10290
10604
|
process.stdout.write(`\u4E0B\u4E00\u6B65\uFF1A${view.nextCommand}
|
|
10291
10605
|
`);
|
|
@@ -10293,7 +10607,7 @@ function writeWorkspaceActiveResult(view, format) {
|
|
|
10293
10607
|
}
|
|
10294
10608
|
function writeWorkspaceBindResult(context, rootDir, format) {
|
|
10295
10609
|
if (format !== "table") {
|
|
10296
|
-
process.stdout.write(
|
|
10610
|
+
process.stdout.write(formatObject22({ ...context, rootDir }, { format }) + "\n");
|
|
10297
10611
|
return;
|
|
10298
10612
|
}
|
|
10299
10613
|
process.stdout.write(
|
|
@@ -10307,7 +10621,7 @@ function writeWorkspaceBindResult(context, rootDir, format) {
|
|
|
10307
10621
|
}
|
|
10308
10622
|
function writeWorkspaceCreateResult(result, format) {
|
|
10309
10623
|
if (format !== "table") {
|
|
10310
|
-
process.stdout.write(
|
|
10624
|
+
process.stdout.write(formatObject22(result, { format }) + "\n");
|
|
10311
10625
|
return;
|
|
10312
10626
|
}
|
|
10313
10627
|
process.stdout.write(
|
|
@@ -10323,7 +10637,7 @@ function writeWorkspaceCreateResult(result, format) {
|
|
|
10323
10637
|
}
|
|
10324
10638
|
function writeWorkspacePullResult(result, format) {
|
|
10325
10639
|
if (format !== "table") {
|
|
10326
|
-
process.stdout.write(
|
|
10640
|
+
process.stdout.write(formatObject22(result, { format }) + "\n");
|
|
10327
10641
|
return;
|
|
10328
10642
|
}
|
|
10329
10643
|
const lines = [
|
|
@@ -10341,7 +10655,7 @@ function writeWorkspacePullResult(result, format) {
|
|
|
10341
10655
|
}
|
|
10342
10656
|
function writeWorkspaceAddMiniResult(result, rootDir, format) {
|
|
10343
10657
|
if (format !== "table") {
|
|
10344
|
-
process.stdout.write(
|
|
10658
|
+
process.stdout.write(formatObject22({ ...result, workspaceRoot: rootDir }, { format }) + "\n");
|
|
10345
10659
|
return;
|
|
10346
10660
|
}
|
|
10347
10661
|
process.stdout.write(
|
|
@@ -10357,7 +10671,7 @@ function writeWorkspaceAddMiniResult(result, rootDir, format) {
|
|
|
10357
10671
|
function writeWorkspaceValidateResult(results, format) {
|
|
10358
10672
|
if (format !== "table") {
|
|
10359
10673
|
process.stdout.write(
|
|
10360
|
-
|
|
10674
|
+
formatObject22(
|
|
10361
10675
|
results.map((item) => ({ artifact: `mini:${item.app.appCode}`, ...item.result })),
|
|
10362
10676
|
{ format }
|
|
10363
10677
|
) + "\n"
|
|
@@ -10370,7 +10684,7 @@ function writeWorkspaceValidateResult(results, format) {
|
|
|
10370
10684
|
errors: item.result.errors.length,
|
|
10371
10685
|
warnings: item.result.warnings.length
|
|
10372
10686
|
}));
|
|
10373
|
-
process.stdout.write(
|
|
10687
|
+
process.stdout.write(formatRows6(rows2, { format: "table" }) + "\n");
|
|
10374
10688
|
for (const item of results) {
|
|
10375
10689
|
if (!item.result.errors.length && !item.result.warnings.length) continue;
|
|
10376
10690
|
process.stdout.write(`
|
|
@@ -10385,7 +10699,7 @@ mini:${item.app.appCode}
|
|
|
10385
10699
|
function writeWorkspacePushResult(rawResult, results, format) {
|
|
10386
10700
|
if (format !== "table") {
|
|
10387
10701
|
process.stdout.write(
|
|
10388
|
-
|
|
10702
|
+
formatObject22(
|
|
10389
10703
|
{
|
|
10390
10704
|
workspaceFiles: { artifact: "workspace", ...rawResult },
|
|
10391
10705
|
miniApps: results.map((item) => ({
|
|
@@ -10414,7 +10728,7 @@ function writeWorkspacePushResult(rawResult, results, format) {
|
|
|
10414
10728
|
);
|
|
10415
10729
|
const conflicts = [...rawConflicts, ...miniConflicts];
|
|
10416
10730
|
if (conflicts.length) {
|
|
10417
|
-
process.stdout.write("conflicts:\n" +
|
|
10731
|
+
process.stdout.write("conflicts:\n" + formatRows6(conflicts, { format: "table" }) + "\n");
|
|
10418
10732
|
return;
|
|
10419
10733
|
}
|
|
10420
10734
|
const rawOperations = rawResult.operations.map((operation) => ({
|
|
@@ -10434,7 +10748,7 @@ function writeWorkspacePushResult(rawResult, results, format) {
|
|
|
10434
10748
|
}))
|
|
10435
10749
|
);
|
|
10436
10750
|
const operations = [...rawOperations, ...miniOperations];
|
|
10437
|
-
process.stdout.write(
|
|
10751
|
+
process.stdout.write(formatRows6(operations, { format: "table" }) + "\n");
|
|
10438
10752
|
if (rawResult.dryRun || results.some((item) => item.result.dryRun)) {
|
|
10439
10753
|
process.stdout.write("dry-run: no remote changes were written\n");
|
|
10440
10754
|
}
|
|
@@ -10444,7 +10758,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
|
|
|
10444
10758
|
const ok = rawOk && reports.every((item) => item.report.ok);
|
|
10445
10759
|
if (format === "json") {
|
|
10446
10760
|
process.stdout.write(
|
|
10447
|
-
|
|
10761
|
+
formatObject22(
|
|
10448
10762
|
{
|
|
10449
10763
|
ok,
|
|
10450
10764
|
workspaceKey: context.workspaceKey,
|
|
@@ -10471,7 +10785,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
|
|
|
10471
10785
|
}
|
|
10472
10786
|
if (format !== "table") {
|
|
10473
10787
|
process.stdout.write(
|
|
10474
|
-
|
|
10788
|
+
formatObject22(
|
|
10475
10789
|
{
|
|
10476
10790
|
ok,
|
|
10477
10791
|
workspaceKey: context.workspaceKey,
|
|
@@ -10580,7 +10894,7 @@ async function requestWorkspaceDeactivation(client3) {
|
|
|
10580
10894
|
}
|
|
10581
10895
|
async function workspaceActivateCommand(workspaceKey, args) {
|
|
10582
10896
|
try {
|
|
10583
|
-
const client3 =
|
|
10897
|
+
const client3 = HcmClient22.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
10584
10898
|
const key2 = normalizeWorkspaceKey(workspaceKey);
|
|
10585
10899
|
await setDevModeBinding(client3, key2);
|
|
10586
10900
|
const fmt = args.output ?? "table";
|
|
@@ -10590,7 +10904,7 @@ async function workspaceActivateCommand(workspaceKey, args) {
|
|
|
10590
10904
|
process.stdout.write("\u8BE5\u7A7A\u95F4\u7684 metas / scripts / menus / mini_apps \u73B0\u5DF2\u5728\u5F53\u524D\u79DF\u6237\u751F\u6548\u3002\n");
|
|
10591
10905
|
} else {
|
|
10592
10906
|
process.stdout.write(
|
|
10593
|
-
|
|
10907
|
+
formatObject22({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
|
|
10594
10908
|
);
|
|
10595
10909
|
}
|
|
10596
10910
|
process.exitCode = 0;
|
|
@@ -10601,7 +10915,7 @@ async function workspaceActivateCommand(workspaceKey, args) {
|
|
|
10601
10915
|
}
|
|
10602
10916
|
async function workspaceDeactivateCommand(args) {
|
|
10603
10917
|
try {
|
|
10604
|
-
const client3 =
|
|
10918
|
+
const client3 = HcmClient22.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
10605
10919
|
const binding = await requestWorkspaceDeactivation(client3);
|
|
10606
10920
|
const result = { ...binding, deactivated: true };
|
|
10607
10921
|
const fmt = args.output ?? "table";
|
|
@@ -10609,7 +10923,7 @@ async function workspaceDeactivateCommand(args) {
|
|
|
10609
10923
|
process.stdout.write("workspace deactivated\n");
|
|
10610
10924
|
process.stdout.write("\u5F53\u524D\u8EAB\u4EFD\u5DF2\u9000\u51FA\u5F00\u53D1\u8005\u6A21\u5F0F\uFF1B\u5F00\u53D1\u7A7A\u95F4\u3001\u672C\u5730\u6587\u4EF6\u4E0E\u5DF2\u53D1\u5E03\u8D44\u4EA7\u5747\u672A\u5220\u9664\u3002\n");
|
|
10611
10925
|
} else {
|
|
10612
|
-
process.stdout.write(
|
|
10926
|
+
process.stdout.write(formatObject22(result, { format: fmt }) + "\n");
|
|
10613
10927
|
}
|
|
10614
10928
|
process.exitCode = 0;
|
|
10615
10929
|
return;
|
|
@@ -10623,10 +10937,10 @@ init_exit();
|
|
|
10623
10937
|
import axios4 from "axios";
|
|
10624
10938
|
import {
|
|
10625
10939
|
AUTH_INFO_PATH,
|
|
10626
|
-
CliError as
|
|
10627
|
-
CliErrorCode as
|
|
10628
|
-
formatObject as
|
|
10629
|
-
formatRows as
|
|
10940
|
+
CliError as CliError24,
|
|
10941
|
+
CliErrorCode as CliErrorCode25,
|
|
10942
|
+
formatObject as formatObject23,
|
|
10943
|
+
formatRows as formatRows7,
|
|
10630
10944
|
fromAxiosError as fromAxiosError21,
|
|
10631
10945
|
loadEnv as loadEnv4,
|
|
10632
10946
|
saveEnv as saveEnv3,
|
|
@@ -10651,8 +10965,8 @@ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
|
|
|
10651
10965
|
const env2 = await loadEnv4(meta2.env);
|
|
10652
10966
|
const accessToken = await TokenStore4.forIdentity(name).getStoredAccessToken();
|
|
10653
10967
|
if (!accessToken) {
|
|
10654
|
-
throw new
|
|
10655
|
-
code:
|
|
10968
|
+
throw new CliError24({
|
|
10969
|
+
code: CliErrorCode25.AUTH_FAILED,
|
|
10656
10970
|
message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
|
|
10657
10971
|
context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
|
|
10658
10972
|
});
|
|
@@ -10680,7 +10994,7 @@ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
|
|
|
10680
10994
|
async function identityShow(name, args) {
|
|
10681
10995
|
try {
|
|
10682
10996
|
const details = await inspectIdentity(name);
|
|
10683
|
-
return exitOk(
|
|
10997
|
+
return exitOk(formatObject23(details, { format: args.output ?? "json" }));
|
|
10684
10998
|
} catch (e) {
|
|
10685
10999
|
exitWithError(axios4.isAxiosError(e) ? fromAxiosError21(e, name) : e);
|
|
10686
11000
|
}
|
|
@@ -10692,7 +11006,7 @@ async function identityList(args) {
|
|
|
10692
11006
|
const names = await listIdentities4(filter);
|
|
10693
11007
|
const fmt = args.output ?? "table";
|
|
10694
11008
|
if (names.length === 0) {
|
|
10695
|
-
return exitOk(fmt === "table" ? "(no identities)" :
|
|
11009
|
+
return exitOk(fmt === "table" ? "(no identities)" : formatObject23([], { format: fmt }));
|
|
10696
11010
|
}
|
|
10697
11011
|
const rows2 = [];
|
|
10698
11012
|
for (const n of names) {
|
|
@@ -10706,7 +11020,7 @@ async function identityList(args) {
|
|
|
10706
11020
|
isDefault: env2?.defaultIdentity === n
|
|
10707
11021
|
});
|
|
10708
11022
|
}
|
|
10709
|
-
return exitOk(fmt === "table" ?
|
|
11023
|
+
return exitOk(fmt === "table" ? formatRows7(rows2, { format: fmt }) : formatObject23(rows2, { format: fmt }));
|
|
10710
11024
|
} catch (e) {
|
|
10711
11025
|
exitWithError(e);
|
|
10712
11026
|
}
|
|
@@ -10715,8 +11029,8 @@ async function identityUse(name) {
|
|
|
10715
11029
|
try {
|
|
10716
11030
|
const meta2 = await loadIdentity4(name);
|
|
10717
11031
|
const env2 = await loadEnv4(meta2.env).catch(() => {
|
|
10718
|
-
throw new
|
|
10719
|
-
code:
|
|
11032
|
+
throw new CliError24({
|
|
11033
|
+
code: CliErrorCode25.IDENTITY_NOT_IN_ENV,
|
|
10720
11034
|
message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
|
|
10721
11035
|
});
|
|
10722
11036
|
});
|
|
@@ -10756,11 +11070,11 @@ init_exit();
|
|
|
10756
11070
|
import { promises as fs9 } from "fs";
|
|
10757
11071
|
import path10 from "path";
|
|
10758
11072
|
import {
|
|
10759
|
-
CliError as
|
|
10760
|
-
CliErrorCode as
|
|
10761
|
-
HcmClient as
|
|
11073
|
+
CliError as CliError25,
|
|
11074
|
+
CliErrorCode as CliErrorCode26,
|
|
11075
|
+
HcmClient as HcmClient23,
|
|
10762
11076
|
fetchReconIdentity,
|
|
10763
|
-
formatObject as
|
|
11077
|
+
formatObject as formatObject24,
|
|
10764
11078
|
httpProbe,
|
|
10765
11079
|
isTempEnv as isTempEnv3,
|
|
10766
11080
|
listIdentities as listIdentities5,
|
|
@@ -10772,7 +11086,7 @@ import {
|
|
|
10772
11086
|
} from "@hcmai/sdk";
|
|
10773
11087
|
async function probeTokenTenant(envName, requested) {
|
|
10774
11088
|
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
10775
|
-
const client3 =
|
|
11089
|
+
const client3 = HcmClient23.fromAuthContext(ctx);
|
|
10776
11090
|
const identity2 = await fetchReconIdentity(httpProbe(client3.raw(), "default"), requested);
|
|
10777
11091
|
return identity2?.tenantId ? String(identity2.tenantId) : void 0;
|
|
10778
11092
|
}
|
|
@@ -10820,8 +11134,8 @@ async function resolveInitEnv(root, args, deps) {
|
|
|
10820
11134
|
if (existing && path10.dirname(existing.path) === path10.resolve(root)) {
|
|
10821
11135
|
const name2 = args.env ?? existing.config.default;
|
|
10822
11136
|
const env2 = existing.config.environments[name2];
|
|
10823
|
-
if (!env2) throw new
|
|
10824
|
-
code:
|
|
11137
|
+
if (!env2) throw new CliError25({
|
|
11138
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10825
11139
|
message: `${existing.path} \u91CC\u6CA1\u6709\u73AF\u5883 '${name2}'\uFF0C\u53EA\u6709\uFF1A${Object.keys(existing.config.environments).join("\u3001")}`,
|
|
10826
11140
|
context: { nextStep: `hcm chiron env add ${name2} --endpoint <\u540E\u7AEF\u5730\u5740>` }
|
|
10827
11141
|
});
|
|
@@ -10830,8 +11144,8 @@ async function resolveInitEnv(root, args, deps) {
|
|
|
10830
11144
|
}
|
|
10831
11145
|
if (args.env) {
|
|
10832
11146
|
const config3 = await loadEnv5(args.env).catch(() => null);
|
|
10833
|
-
if (!config3?.endpoint) throw new
|
|
10834
|
-
code:
|
|
11147
|
+
if (!config3?.endpoint) throw new CliError25({
|
|
11148
|
+
code: CliErrorCode26.ENV_NOT_FOUND,
|
|
10835
11149
|
message: `\u672C\u673A\u6CA1\u6709\u540D\u53EB '${args.env}' \u7684\u73AF\u5883\u3002`,
|
|
10836
11150
|
context: { nextStep: "`hcm env list` \u770B\u6709\u54EA\u4E9B\uFF1B\u6216\u5B8C\u5168\u663E\u5F0F\u5730\u5EFA\uFF1A`hcm chiron init --endpoint <\u540E\u7AEF\u5730\u5740> --tenant <\u79DF\u6237\u53F7>`" }
|
|
10837
11151
|
});
|
|
@@ -10841,14 +11155,14 @@ async function resolveInitEnv(root, args, deps) {
|
|
|
10841
11155
|
const name = g.activeEnv;
|
|
10842
11156
|
const config2 = name ? await loadEnv5(name).catch(() => null) : null;
|
|
10843
11157
|
const explicitPaths = " hcm chiron init --env <\u672C\u673A\u73AF\u5883\u540D>\uFF08hcm env list \u770B\u6709\u54EA\u4E9B\uFF09\n hcm chiron init --endpoint <\u540E\u7AEF\u5730\u5740> --tenant <\u79DF\u6237\u53F7>\uFF08\u5B8C\u5168\u663E\u5F0F\uFF0C\u4E0D\u9700\u8981\u5148\u767B\u5F55\uFF09";
|
|
10844
|
-
if (!config2?.endpoint) throw new
|
|
10845
|
-
code:
|
|
11158
|
+
if (!config2?.endpoint) throw new CliError25({
|
|
11159
|
+
code: CliErrorCode26.ENV_NOT_FOUND,
|
|
10846
11160
|
message: "\u6CA1\u8BF4\u8FD9\u4E2A\u9879\u76EE\u5BF9\u7740\u54EA\u4E2A\u73AF\u5883\uFF0C\u672C\u673A\u4E5F\u6CA1\u6709\u53EF\u7528\u7684\u6D3B\u52A8\u73AF\u5883\u3002",
|
|
10847
11161
|
context: { nextStep: `\u4E8C\u9009\u4E00\uFF1A
|
|
10848
11162
|
${explicitPaths}` }
|
|
10849
11163
|
});
|
|
10850
|
-
if (isTempEnv3(name)) throw new
|
|
10851
|
-
code:
|
|
11164
|
+
if (isTempEnv3(name)) throw new CliError25({
|
|
11165
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10852
11166
|
message: `\u672C\u673A\u6D3B\u52A8\u73AF\u5883\u662F\u4E34\u65F6\u7684\uFF08${config2.endpoint}\uFF09\uFF0C\u8FD8\u6CA1\u6709\u540D\u5B57\u3002\u9879\u76EE\u8981\u7ED1\u4E00\u4E2A\u7A33\u5B9A\u7684\u73AF\u5883\uFF0C\u5426\u5219\u4E0B\u4E00\u6B21 hcm login --code \u8986\u76D6\u5B83\u4E4B\u540E\uFF0C\u4ED3\u91CC\u8BB0\u7684\u5C31\u5BF9\u4E0D\u4E0A\u4E86\u3002`,
|
|
10853
11167
|
context: { nextStep: `\u5148\u7ED9\u5B83\u8D77\u4E2A\u540D\u5B57\uFF1Ahcm env save <name>\uFF1B\u6216\u76F4\u63A5\u663E\u5F0F\u5EFA\uFF1A
|
|
10854
11168
|
${explicitPaths}` }
|
|
@@ -10856,8 +11170,8 @@ ${explicitPaths}` }
|
|
|
10856
11170
|
const summary = `${name} \xB7 ${config2.endpoint} \xB7 \u79DF\u6237 ${config2.tenantId ?? "1"}`;
|
|
10857
11171
|
if (!args.yes) {
|
|
10858
11172
|
const ok = deps.isTty() && deps.confirm ? await deps.confirm(`\u6CA1\u6307\u5B9A\u73AF\u5883\uFF0C\u7528\u672C\u673A\u5F53\u524D\u6D3B\u52A8\u7684 ${summary} \u5417\uFF1F[y/N] `) : false;
|
|
10859
|
-
if (!ok) throw new
|
|
10860
|
-
code:
|
|
11173
|
+
if (!ok) throw new CliError25({
|
|
11174
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10861
11175
|
message: `\u6CA1\u786E\u8BA4\u8981\u7528\u672C\u673A\u6D3B\u52A8\u73AF\u5883\uFF08${summary}\uFF09\u3002\u9879\u76EE\u73AF\u5883\u4F1A\u63D0\u4EA4\u8FDB\u4ED3\u3001\u5F71\u54CD\u6240\u6709\u534F\u4F5C\u8005\uFF0C\u4E0D\u9760\u4E0A\u4E00\u6761\u547D\u4EE4\u7684\u526F\u4F5C\u7528\u51B3\u5B9A\u3002`,
|
|
10862
11176
|
context: { nextStep: `\u786E\u8BA4\u5C31\u52A0 --yes\uFF1B\u6216\u660E\u8BF4\uFF1A
|
|
10863
11177
|
${explicitPaths}` }
|
|
@@ -10873,16 +11187,16 @@ async function scaffoldChironProject(root, env2, envName) {
|
|
|
10873
11187
|
const document2 = parseEnvYaml(existing);
|
|
10874
11188
|
const recorded = Object.values(document2.environments).find((candidate) => candidate.endpoint === env2.endpoint && candidate.tenant === env2.tenant) ?? document2.environments[document2.default];
|
|
10875
11189
|
if (recorded.endpoint !== env2.endpoint) {
|
|
10876
|
-
throw new
|
|
10877
|
-
code:
|
|
11190
|
+
throw new CliError25({
|
|
11191
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10878
11192
|
message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env2.endpoint}\uFF08env '${envName}'\uFF09\u3002
|
|
10879
11193
|
\u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
|
|
10880
11194
|
\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`
|
|
10881
11195
|
});
|
|
10882
11196
|
}
|
|
10883
11197
|
if (recorded.tenant !== env2.tenant) {
|
|
10884
|
-
throw new
|
|
10885
|
-
code:
|
|
11198
|
+
throw new CliError25({
|
|
11199
|
+
code: CliErrorCode26.INVALID_ARGUMENT,
|
|
10886
11200
|
message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env2.tenant}\u3002
|
|
10887
11201
|
\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
|
|
10888
11202
|
});
|
|
@@ -10957,7 +11271,7 @@ async function chironInitCommand(args, deps) {
|
|
|
10957
11271
|
const result = await runChironInit(args, deps);
|
|
10958
11272
|
const fmt = args.output ?? "table";
|
|
10959
11273
|
if (fmt === "json" || fmt === "yaml") {
|
|
10960
|
-
process.stdout.write(
|
|
11274
|
+
process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
|
|
10961
11275
|
} else {
|
|
10962
11276
|
const mark = { verified: "\u2705", mismatch: "\u274C", unreachable: "\u26A0\uFE0F", skipped: "\xB7" }[result.tenantCheck.status];
|
|
10963
11277
|
process.stdout.write(
|
|
@@ -10979,9 +11293,9 @@ async function chironInitCommand(args, deps) {
|
|
|
10979
11293
|
// src/commands/gap.ts
|
|
10980
11294
|
import { readFileSync as readFileSync6 } from "fs";
|
|
10981
11295
|
import {
|
|
10982
|
-
CliErrorCode as
|
|
11296
|
+
CliErrorCode as CliErrorCode28,
|
|
10983
11297
|
createHttpClient as createHttpClient4,
|
|
10984
|
-
formatObject as
|
|
11298
|
+
formatObject as formatObject25,
|
|
10985
11299
|
loadGlobalConfig as loadGlobalConfig10,
|
|
10986
11300
|
resolveEnvContext as resolveEnvContext7,
|
|
10987
11301
|
printResolvedEnvironment as printResolvedEnvironment7
|
|
@@ -11376,7 +11690,7 @@ async function gapComments({ client: client3 }, ref, { limit } = {}, casesSlug =
|
|
|
11376
11690
|
}
|
|
11377
11691
|
|
|
11378
11692
|
// src/jira/gap-verify.ts
|
|
11379
|
-
import { CASES_REPO_SLUG as CASES_REPO_SLUG3, CliError as
|
|
11693
|
+
import { CASES_REPO_SLUG as CASES_REPO_SLUG3, CliError as CliError26, CliErrorCode as CliErrorCode27, JiraHttpError, firstLine as firstLine2, parseRef as parseRef2 } from "@hcmai/sdk";
|
|
11380
11694
|
var VERIFY_RESULTS = ["pass", "fail", "partial"];
|
|
11381
11695
|
var WRITTEN_TAG = { no: "\u3010\u672A\u5199\u5165\u3011", yes: "\u3010\u5DF2\u5199\u5165\u3011", unknown: "\u3010\u5199\u6CA1\u5199\u4E0D\u786E\u5B9A\u3011" };
|
|
11382
11696
|
var FIXED_STATUS = "\u5DF2\u4FEE\u590D";
|
|
@@ -11390,14 +11704,14 @@ var VERIFY_PLAN = {
|
|
|
11390
11704
|
function parseVerifyResult(raw) {
|
|
11391
11705
|
const v = String(raw ?? "").trim().toLowerCase();
|
|
11392
11706
|
if (VERIFY_RESULTS.includes(v)) return v;
|
|
11393
|
-
throw new
|
|
11394
|
-
code: raw === void 0 ?
|
|
11707
|
+
throw new CliError26({
|
|
11708
|
+
code: raw === void 0 ? CliErrorCode27.MISSING_FLAG : CliErrorCode27.INVALID_ARGUMENT,
|
|
11395
11709
|
message: `--result \u53EA\u80FD\u662F pass / fail / partial\uFF0C\u7ED9\u7684\u662F\u300C${raw ?? "\uFF08\u6CA1\u7ED9\uFF09"}\u300D`,
|
|
11396
11710
|
context: { nextStep: "pass = \u539F\u6545\u969C\u5728\u76EE\u6807\u73AF\u5883\u4E0D\u518D\u51FA\u73B0\uFF1Bfail = \u4ECD\u7136\u590D\u73B0\u6216\u9A8C\u51FA\u6CA1\u901A\u8FC7\u7684\uFF1Bpartial = \u53EA\u9A8C\u4E86\u4E00\u90E8\u5206\u3001\u9A8C\u8FC7\u7684\u90FD\u901A\u8FC7\uFF08\u4E0D\u5173\u5355\uFF09\u3002" }
|
|
11397
11711
|
});
|
|
11398
11712
|
}
|
|
11399
11713
|
function verifyFailure(reasonCode, code, written, message, nextStep, extra = {}, cause) {
|
|
11400
|
-
return new
|
|
11714
|
+
return new CliError26({ code, message: `${message}${WRITTEN_TAG[written]}`, context: { reasonCode, written, nextStep, ...extra }, cause });
|
|
11401
11715
|
}
|
|
11402
11716
|
function who(u) {
|
|
11403
11717
|
if (!u) return "\uFF08\u5355\u4E0A\u6CA1\u6709\uFF09";
|
|
@@ -11473,7 +11787,7 @@ function unconfirmedWhy(e) {
|
|
|
11473
11787
|
}
|
|
11474
11788
|
function writeFailure(e, key2, what) {
|
|
11475
11789
|
if (e instanceof JiraHttpError && e.status >= 400 && e.status < 500) {
|
|
11476
|
-
return verifyFailure("write-rejected",
|
|
11790
|
+
return verifyFailure("write-rejected", CliErrorCode27.BUSINESS_RULE_VIOLATION, "no", `Jira \u4EE5 ${e.status} \u62D2\u7EDD\u4E86\u8FD9\u6B21${what}`, rejectNextStep(e.status, key2), {
|
|
11477
11791
|
key: key2,
|
|
11478
11792
|
status: e.status,
|
|
11479
11793
|
details: e.message
|
|
@@ -11481,7 +11795,7 @@ function writeFailure(e, key2, what) {
|
|
|
11481
11795
|
}
|
|
11482
11796
|
return verifyFailure(
|
|
11483
11797
|
"write-unconfirmed",
|
|
11484
|
-
|
|
11798
|
+
CliErrorCode27.NETWORK_ERROR,
|
|
11485
11799
|
"unknown",
|
|
11486
11800
|
`${what}\u8BF7\u6C42\u6CA1\u5F97\u5230\u786E\u8BA4\uFF08${unconfirmedWhy(e)}\uFF09`,
|
|
11487
11801
|
`\u5148\u7528 \`hcm chiron gap status ${key2}\` \u4E0E \`hcm chiron gap comments ${key2}\` \u6838\u5BF9\u5199\u8FDB\u53BB\u6CA1\u6709\uFF0C\u518D\u51B3\u5B9A\u8981\u4E0D\u8981\u91CD\u8DD1\u2014\u2014partial \u91CD\u8DD1\u4F1A\u591A\u4E00\u6761\u8BC4\u8BBA\u3002`,
|
|
@@ -11504,7 +11818,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11504
11818
|
if (!parsed || parsed.kind !== "jira") {
|
|
11505
11819
|
throw verifyFailure(
|
|
11506
11820
|
"not-jira-key",
|
|
11507
|
-
|
|
11821
|
+
CliErrorCode27.INVALID_ARGUMENT,
|
|
11508
11822
|
"no",
|
|
11509
11823
|
parsed && parsed.kind === "repo" ? `${parsed.repo}#${parsed.number} \u662F\u4EA7\u54C1\u4ED3\u7F16\u53F7\uFF0C\u9A8C\u6536\u8981\u843D\u5728 Jira \u5355\u4E0A` : `\u770B\u4E0D\u61C2 ${ref}`,
|
|
11510
11824
|
"\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12 \u6216\u88F8\u6570\u5B57 12\uFF09\u2014\u2014\u5C31\u662F `hcm chiron gap submit` \u56DE\u6267\u91CC\u7684\u90A3\u4E2A\u7F16\u53F7\u3002"
|
|
@@ -11514,7 +11828,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11514
11828
|
const inProject = (k) => k.startsWith(`${client3.project}-`);
|
|
11515
11829
|
const wrongProject = (k) => verifyFailure(
|
|
11516
11830
|
"wrong-project",
|
|
11517
|
-
|
|
11831
|
+
CliErrorCode27.INVALID_ARGUMENT,
|
|
11518
11832
|
"no",
|
|
11519
11833
|
`${k} \u4E0D\u5728 ${client3.project} \u9879\u76EE\u91CC\uFF0C\u9A8C\u6536\u53EA\u5199 ${client3.project} \u7684\u5355`,
|
|
11520
11834
|
`\u7ED9 ${client3.project} \u7684\u5355\u53F7\uFF08\`hcm chiron gap submit\` \u56DE\u6267\u91CC\u7684\u90A3\u4E2A\uFF09\u3002\u522B\u7684\u9879\u76EE\u7684\u5355\u8FD9\u6761\u547D\u4EE4\u4E0D\u78B0\u2014\u2014\u90A3\u91CC\u7684\u72B6\u6001\u540D\u4E0E\u6D41\u8F6C\u540D\u548C ${client3.project} \u540C\u5F62\uFF0C\u5199\u9519\u4E86\u4F1A\u628A\u522B\u5904\u7684\u5355\u5173\u6389\u3002`,
|
|
@@ -11525,7 +11839,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11525
11839
|
if (evidence.length < EVIDENCE_MIN) {
|
|
11526
11840
|
throw verifyFailure(
|
|
11527
11841
|
"evidence-too-short",
|
|
11528
|
-
|
|
11842
|
+
CliErrorCode27.INVALID_ARGUMENT,
|
|
11529
11843
|
"no",
|
|
11530
11844
|
`\u9A8C\u6536\u8BC1\u636E\u81F3\u5C11 ${EVIDENCE_MIN} \u4E2A\u5B57\uFF0C\u7ED9\u7684\u662F ${evidence.length} \u4E2A\u5B57`,
|
|
11531
11845
|
"\u5199\u6E05\uFF1A\u54EA\u4E2A\u73AF\u5883\u3001\u54EA\u4E2A\u7248\u672C\uFF08`hcm version`\uFF09\u3001\u6309\u6280\u80FD\u8DD1\u4E86\u4EC0\u4E48\u3001\u770B\u5230\u4E86\u4EC0\u4E48\uFF1B\u8BC1\u636E\u6587\u4EF6\u653E\u5728 evidence/ \u4E0B\u5E76\u5199\u4E0A\u8DEF\u5F84\u3002",
|
|
@@ -11551,7 +11865,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11551
11865
|
if (!sameUser(reporter, me)) {
|
|
11552
11866
|
throw verifyFailure(
|
|
11553
11867
|
"not-reporter",
|
|
11554
|
-
|
|
11868
|
+
CliErrorCode27.BUSINESS_RULE_VIOLATION,
|
|
11555
11869
|
"no",
|
|
11556
11870
|
`\u53EA\u6709\u63D0\u5355\u4EBA\u80FD\u9A8C\u6536 ${key2}\uFF1A\u63D0\u5355\u4EBA\u662F ${who(reporter)}\uFF0C\u5F53\u524D\u8EAB\u4EFD\u662F ${who(me)}`,
|
|
11557
11871
|
"\u8BF7\u63D0\u5355\u4EBA\u590D\u9A8C\u540E\u81EA\u5DF1\u8DD1\u8FD9\u6761\u547D\u4EE4\u3002\u4F60\u624B\u4E0A\u7684\u65B0\u73B0\u573A\u7528 `hcm chiron gap submit` \u8FFD\u52A0\uFF1B\u7ECF\u529E\u4EBA\u3001\u641C\u7D22\u547D\u4E2D\u3001\u5728\u522B\u4EBA\u7684\u5355\u4E0B\u8FFD\u52A0\u8FC7\u73B0\u573A\u90FD\u4E0D\u6784\u6210\u9A8C\u6536\u8D44\u683C\u3002",
|
|
@@ -11565,7 +11879,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11565
11879
|
if (status !== FIXED_STATUS) {
|
|
11566
11880
|
throw verifyFailure(
|
|
11567
11881
|
"status-not-fixed",
|
|
11568
|
-
|
|
11882
|
+
CliErrorCode27.BUSINESS_RULE_VIOLATION,
|
|
11569
11883
|
"no",
|
|
11570
11884
|
`${key2} \u7684\u72B6\u6001\u662F\u300C${status ?? "?"}\u300D\uFF0C\u9A8C\u6536\u53EA\u5728\u300C${FIXED_STATUS}\u300D\u4E0A\u505A`,
|
|
11571
11885
|
notFixedNextStep(key2, status, o.result),
|
|
@@ -11584,7 +11898,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11584
11898
|
const available = list.map((t) => `${t.name}\u2192${t.to?.name ?? "?"}`);
|
|
11585
11899
|
throw verifyFailure(
|
|
11586
11900
|
"transition-unavailable",
|
|
11587
|
-
|
|
11901
|
+
CliErrorCode27.BUSINESS_RULE_VIOLATION,
|
|
11588
11902
|
"no",
|
|
11589
11903
|
`${key2} \u4E0A\u670D\u52A1\u7AEF\u6B64\u523B\u4E0D\u7ED9\u300C${want.name}\u2192${want.to}\u300D\u8FD9\u6761\u6D41\u8F6C\uFF08\u53EF\u7528\uFF1A${available.join(" / ") || "\uFF08\u65E0\uFF09"}\uFF09`,
|
|
11590
11904
|
"\u591A\u534A\u662F\u5DE5\u4F5C\u6D41\u88AB\u6539\u8FC7\uFF0C\u6216\u4F60\u7684\u8D26\u53F7\u5728\u8FD9\u4E2A\u9879\u76EE\u4E0A\u6CA1\u6709\u8FD9\u6761\u6D41\u8F6C\u7684\u6743\u9650\u3002\u628A\u8FD9\u6BB5\u8F93\u51FA\u53D1\u7ED9\u4EA7\u54C1\u4FA7\u5206\u8BCA\u4EBA\uFF1B\u522B\u81EA\u5DF1\u62FC HTTP\uFF0C\u4E5F\u522B\u6539\u95EE\u9898\u7C7B\u578B\u7ED5\u8FC7\u3002",
|
|
@@ -11596,7 +11910,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11596
11910
|
else if (req.missing.length) {
|
|
11597
11911
|
throw verifyFailure(
|
|
11598
11912
|
"required-fields-missing",
|
|
11599
|
-
|
|
11913
|
+
CliErrorCode27.BUSINESS_RULE_VIOLATION,
|
|
11600
11914
|
"no",
|
|
11601
11915
|
`\u300C${transition.name}\u300D\u8981\u6C42\u8FD9\u4E9B\u5B57\u6BB5\u6709\u503C\uFF0C${key2} \u4E0A\u662F\u7A7A\u7684\uFF1A${req.missing.join("\u3001")}`,
|
|
11602
11916
|
"\u8FD9\u4E9B\u5B57\u6BB5\u7531\u4EA7\u54C1\u4FA7\u7EF4\u62A4\uFF0C\u8BF7\u5206\u8BCA\u4EBA\u8865\u9F50\u540E\u518D\u8DD1\uFF1BCLI \u4E0D\u4EE3\u586B\uFF0C\u4E5F\u522B\u628A\u7ECF\u529E\u4EBA\u6216\u4FEE\u590D\u4EBA\u731C\u6210 Bug\u5F15\u5165\u4EBA\u3002",
|
|
@@ -11637,7 +11951,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11637
11951
|
} catch (e) {
|
|
11638
11952
|
throw verifyFailure(
|
|
11639
11953
|
"readback-failed",
|
|
11640
|
-
|
|
11954
|
+
CliErrorCode27.NETWORK_ERROR,
|
|
11641
11955
|
"yes",
|
|
11642
11956
|
`${what}\u5DF2\u88AB Jira \u63A5\u53D7\uFF0C\u4F46\u56DE\u8BFB ${key2} \u5931\u8D25\uFF0C\u843D\u5230\u4EC0\u4E48\u72B6\u6001\u6CA1\u786E\u8BA4`,
|
|
11643
11957
|
`\u7528 \`hcm chiron gap status ${key2}\` \u770B\u7ED3\u679C\uFF1B\u522B\u76F4\u63A5\u91CD\u8DD1\uFF08\u4F1A\u518D\u5199\u4E00\u6761\u8BC4\u8BBA\uFF09\u3002`,
|
|
@@ -11651,7 +11965,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11651
11965
|
const did = plan.outcome === "closed" ? "\u5173\u5355" : "\u9000\u56DE";
|
|
11652
11966
|
throw verifyFailure(
|
|
11653
11967
|
"readback-mismatch",
|
|
11654
|
-
|
|
11968
|
+
CliErrorCode27.SERVER_ERROR,
|
|
11655
11969
|
"yes",
|
|
11656
11970
|
after2.status !== expected ? `${what}\u5DF2\u88AB Jira \u63A5\u53D7\uFF0C\u4F46\u56DE\u8BFB ${key2} \u7684\u72B6\u6001\u662F\u300C${after2.status ?? "?"}\u300D\uFF0C\u9884\u671F\u300C${expected}\u300D` : `${what}\u5DF2\u88AB Jira \u63A5\u53D7\uFF0C${key2} \u56DE\u5230\u4E86\u300C${expected}\u300D\uFF0C\u4F46 resolution \u8FD8\u662F\u300C${after2.resolution}\u300D\u2014\u2014\u5B83\u4F1A\u4ECE\u300C\u672A\u89E3\u51B3\u300D\u7684\u67E5\u8BE2\u91CC\u6D88\u5931`,
|
|
11657
11971
|
after2.status !== expected ? `\u4EE5 \`hcm chiron gap status ${key2}\` \u4E3A\u51C6\uFF0C\u522B\u5F53\u6210\u5DF2\u7ECF${did}\uFF1B\u628A\u8FD9\u6BB5\u8F93\u51FA\u53D1\u7ED9\u4EA7\u54C1\u4FA7\u5206\u8BCA\u4EBA\u3002` : "\u8BF7\u4EA7\u54C1\u4FA7\u5206\u8BCA\u4EBA\u6E05\u6389\u8FD9\u5355\u7684 resolution\uFF08\u300C\u672A\u89E3\u51B3\u300D\u8FD9\u6761\u6D41\u8F6C\u672C\u6765\u4F1A\u6E05\uFF0C\u6CA1\u6E05\u8BF4\u660E\u5DE5\u4F5C\u6D41\u88AB\u6539\u8FC7\uFF09\uFF1B\u628A\u8FD9\u6BB5\u8F93\u51FA\u53D1\u7ED9\u4ED6\u3002",
|
|
@@ -11682,7 +11996,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11682
11996
|
} catch (e) {
|
|
11683
11997
|
throw verifyFailure(
|
|
11684
11998
|
"readback-failed",
|
|
11685
|
-
|
|
11999
|
+
CliErrorCode27.NETWORK_ERROR,
|
|
11686
12000
|
"yes",
|
|
11687
12001
|
`\u8BC4\u8BBA\u5DF2\u88AB Jira \u63A5\u53D7\uFF0C\u4F46\u56DE\u8BFB ${key2} \u7684\u8BC4\u8BBA\u5931\u8D25\uFF0C\u6CA1\u786E\u8BA4\u5B83\u5728`,
|
|
11688
12002
|
`\u7528 \`hcm chiron gap comments ${key2}\` \u770B\u5B83\u5728\u4E0D\u5728\uFF1B\u522B\u76F4\u63A5\u91CD\u8DD1\uFF08\u4F1A\u518D\u5199\u4E00\u6761\uFF09\u3002`,
|
|
@@ -11696,7 +12010,7 @@ async function gapVerify({ client: client3 }, ref, o, casesSlug = CASES_REPO_SLU
|
|
|
11696
12010
|
} else if (!listed.some((c) => c.id === written.id)) {
|
|
11697
12011
|
throw verifyFailure(
|
|
11698
12012
|
"readback-mismatch",
|
|
11699
|
-
|
|
12013
|
+
CliErrorCode27.SERVER_ERROR,
|
|
11700
12014
|
"yes",
|
|
11701
12015
|
`Jira \u56DE\u4E86\u8BC4\u8BBA ${written.id}\uFF0C\u4F46\u56DE\u8BFB ${key2} \u7684\u8BC4\u8BBA\u91CC\u6CA1\u6709\u5B83`,
|
|
11702
12016
|
`\u7528 \`hcm chiron gap comments ${key2}\` \u6838\u5BF9\uFF1B\u522B\u76F4\u63A5\u91CD\u8DD1\uFF0C\u628A\u8FD9\u6BB5\u8F93\u51FA\u53D1\u7ED9\u4EA7\u54C1\u4FA7\u5206\u8BCA\u4EBA\u3002`,
|
|
@@ -11732,7 +12046,7 @@ async function gapDeps(deps) {
|
|
|
11732
12046
|
return { client: await deps.client() };
|
|
11733
12047
|
}
|
|
11734
12048
|
function emit5(fmt, data, text) {
|
|
11735
|
-
if (fmt === "json" || fmt === "yaml") process.stdout.write(
|
|
12049
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject25(data, { format: fmt }) + "\n");
|
|
11736
12050
|
else process.stdout.write(text() + "\n");
|
|
11737
12051
|
}
|
|
11738
12052
|
async function run2(fn) {
|
|
@@ -11835,7 +12149,7 @@ function readEvidence(opts, stdinIsTTY = !!process.stdin.isTTY, readStdin2 = ()
|
|
|
11835
12149
|
if (opts.file !== void 0 && opts.body !== void 0) {
|
|
11836
12150
|
throw verifyFailure(
|
|
11837
12151
|
"evidence-ambiguous",
|
|
11838
|
-
|
|
12152
|
+
CliErrorCode28.INVALID_ARGUMENT,
|
|
11839
12153
|
"no",
|
|
11840
12154
|
"--body \u4E0E --file \u540C\u65F6\u7ED9\u4E86\uFF0C\u4E0D\u77E5\u9053\u8BE5\u7528\u54EA\u4EFD\u505A\u9A8C\u6536\u8BC1\u636E",
|
|
11841
12155
|
"\u53EA\u7559\u4E00\u4E2A\uFF1A\u77ED\u8BC1\u636E\u7528 --body\uFF0C\u957F\u8BC1\u636E\u5199\u8FDB\u6587\u4EF6\u7528 --file\u3002"
|
|
@@ -11847,7 +12161,7 @@ function readEvidence(opts, stdinIsTTY = !!process.stdin.isTTY, readStdin2 = ()
|
|
|
11847
12161
|
} catch (e) {
|
|
11848
12162
|
throw verifyFailure(
|
|
11849
12163
|
"evidence-unreadable",
|
|
11850
|
-
|
|
12164
|
+
CliErrorCode28.INVALID_ARGUMENT,
|
|
11851
12165
|
"no",
|
|
11852
12166
|
`\u8BFB\u4E0D\u5230\u8BC1\u636E\u6587\u4EF6 ${opts.file}`,
|
|
11853
12167
|
"\u6838\u5BF9\u8DEF\u5F84\u4E0E\u6743\u9650\uFF1B\u8BC1\u636E\u6587\u4EF6\u4E00\u822C\u653E\u5728\u9879\u76EE\u4ED3\u7684 evidence/ \u4E0B\u3002",
|
|
@@ -11860,7 +12174,7 @@ function readEvidence(opts, stdinIsTTY = !!process.stdin.isTTY, readStdin2 = ()
|
|
|
11860
12174
|
if (stdinIsTTY) {
|
|
11861
12175
|
throw verifyFailure(
|
|
11862
12176
|
"evidence-missing",
|
|
11863
|
-
|
|
12177
|
+
CliErrorCode28.INVALID_ARGUMENT,
|
|
11864
12178
|
"no",
|
|
11865
12179
|
"\u6CA1\u7ED9\u9A8C\u6536\u8BC1\u636E",
|
|
11866
12180
|
"\u7528 --body <\u6587\u672C> \u6216 --file <\u6587\u4EF6> \u7ED9\u51FA\uFF1A\u54EA\u4E2A\u73AF\u5883\u3001\u54EA\u4E2A\u7248\u672C\u3001\u6309\u6280\u80FD\u8DD1\u4E86\u4EC0\u4E48\u3001\u770B\u5230\u4E86\u4EC0\u4E48\u3002"
|
|
@@ -11918,26 +12232,26 @@ init_exit();
|
|
|
11918
12232
|
import { promises as fs10 } from "fs";
|
|
11919
12233
|
import path11 from "path";
|
|
11920
12234
|
import {
|
|
11921
|
-
HcmClient as
|
|
11922
|
-
CliError as
|
|
11923
|
-
CliErrorCode as
|
|
12235
|
+
HcmClient as HcmClient24,
|
|
12236
|
+
CliError as CliError27,
|
|
12237
|
+
CliErrorCode as CliErrorCode29,
|
|
11924
12238
|
loadGlobalConfig as loadGlobalConfig11,
|
|
11925
12239
|
resolveEnvContext as resolveEnvContext8,
|
|
11926
12240
|
fetchReconIdentity as fetchReconIdentity2,
|
|
11927
|
-
formatObject as
|
|
12241
|
+
formatObject as formatObject26,
|
|
11928
12242
|
httpProbe as httpProbe2,
|
|
11929
|
-
conversationWebSocketEndpoint as
|
|
12243
|
+
conversationWebSocketEndpoint as conversationWebSocketEndpoint4,
|
|
11930
12244
|
probeConversationHandshake,
|
|
11931
12245
|
runDoctor
|
|
11932
12246
|
} from "@hcmai/sdk";
|
|
11933
12247
|
var defaultDeps2 = {
|
|
11934
12248
|
anchors: async (envName, tenant2, as, project) => {
|
|
11935
12249
|
const ctx = await getActiveAuthContextFromCli({ env: envName, as }, { cwd: project });
|
|
11936
|
-
const client3 =
|
|
12250
|
+
const client3 = HcmClient24.fromAuthContext(ctx);
|
|
11937
12251
|
const probe = httpProbe2(client3.raw(), "default");
|
|
11938
12252
|
const identity2 = await fetchReconIdentity2(probe, tenant2);
|
|
11939
12253
|
const report = await runDoctor(probe, identity2, () => probeConversationHandshake({
|
|
11940
|
-
endpoint:
|
|
12254
|
+
endpoint: conversationWebSocketEndpoint4(ctx.endpoint),
|
|
11941
12255
|
getAccessToken: () => client3.getAccessToken()
|
|
11942
12256
|
}));
|
|
11943
12257
|
return { report, tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
|
|
@@ -11971,8 +12285,8 @@ async function runChironDoctor(args, deps = defaultDeps2) {
|
|
|
11971
12285
|
if (args.env !== void 0 && !Object.hasOwn(file.environments, args.env)) {
|
|
11972
12286
|
try {
|
|
11973
12287
|
explicitSlot = await resolveEnvContext8({ envFlag: args.env, cwd: root }, process.env, await loadGlobalConfig11());
|
|
11974
|
-
if (!explicitSlot.project) throw new
|
|
11975
|
-
code:
|
|
12288
|
+
if (!explicitSlot.project) throw new CliError27({
|
|
12289
|
+
code: CliErrorCode29.INVALID_ARGUMENT,
|
|
11976
12290
|
message: `\u672C\u673A\u69FD '${args.env}' \u7684\u5730\u5740\u6216\u79DF\u6237\u4E0D\u5339\u914D\u672C\u9879\u76EE\uFF1B\u672C\u9879\u76EE\u6709\uFF1A${names.join(", ")}`
|
|
11977
12291
|
});
|
|
11978
12292
|
selectedName = explicitSlot.project.name;
|
|
@@ -12026,7 +12340,7 @@ async function runChironDoctor(args, deps = defaultDeps2) {
|
|
|
12026
12340
|
});
|
|
12027
12341
|
}
|
|
12028
12342
|
} catch (e) {
|
|
12029
|
-
const msg = e instanceof
|
|
12343
|
+
const msg = e instanceof CliError27 ? e.message : e.message;
|
|
12030
12344
|
report.lines.push({ item: "\u767B\u5F55", verdict: severity(), detail: `${label} \xB7 \u672C\u673A\u69FD ${found.name} \xB7 ${env3.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
|
|
12031
12345
|
}
|
|
12032
12346
|
}
|
|
@@ -12102,7 +12416,7 @@ async function chironDoctorCommand(args, deps) {
|
|
|
12102
12416
|
try {
|
|
12103
12417
|
const report = await runChironDoctor(args, deps);
|
|
12104
12418
|
const fmt = args.output ?? "table";
|
|
12105
|
-
if (fmt === "json" || fmt === "yaml") process.stdout.write(
|
|
12419
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject26(report, { format: fmt }) + "\n");
|
|
12106
12420
|
else process.stdout.write(renderChironDoctor(report) + "\n");
|
|
12107
12421
|
process.exitCode = report.ok ? 0 : 1;
|
|
12108
12422
|
} catch (e) {
|
|
@@ -12117,12 +12431,12 @@ import path12 from "path";
|
|
|
12117
12431
|
import yaml from "js-yaml";
|
|
12118
12432
|
import {
|
|
12119
12433
|
AUTH_INFO_PATH as AUTH_INFO_PATH2,
|
|
12120
|
-
CliError as
|
|
12121
|
-
CliErrorCode as
|
|
12434
|
+
CliError as CliError28,
|
|
12435
|
+
CliErrorCode as CliErrorCode30,
|
|
12122
12436
|
discoverProjectEnv as discoverProjectEnv6,
|
|
12123
12437
|
ENV_FILE as ENV_FILE2,
|
|
12124
12438
|
findEnvByEndpoint as findEnvByEndpoint5,
|
|
12125
|
-
formatObject as
|
|
12439
|
+
formatObject as formatObject27,
|
|
12126
12440
|
listIdentities as listIdentities6,
|
|
12127
12441
|
parseEnvYaml as parseEnvYaml2,
|
|
12128
12442
|
renderEnvYaml as renderEnvYaml2,
|
|
@@ -12141,7 +12455,7 @@ function summarizeReasons(reasons) {
|
|
|
12141
12455
|
return reasons.length === 1 ? reasons[0] : `${reasons[0]} \u7B49 ${reasons.length} \u6761\uFF08--output json \u770B\u5168\u90E8\uFF09`;
|
|
12142
12456
|
}
|
|
12143
12457
|
function invalid2(message, nextStep) {
|
|
12144
|
-
throw new
|
|
12458
|
+
throw new CliError28({ code: CliErrorCode30.INVALID_ARGUMENT, message, context: { nextStep } });
|
|
12145
12459
|
}
|
|
12146
12460
|
function required(value, label) {
|
|
12147
12461
|
if (!value?.trim()) invalid2(`${label} \u4E0D\u80FD\u4E3A\u7A7A\uFF1B\u914D\u7F6E\u672A\u5199\u5165\u3002`, `\u8BF7\u63D0\u4F9B\u975E\u7A7A\u7684 ${label}`);
|
|
@@ -12324,7 +12638,7 @@ async function runChironEnv(action, args = {}) {
|
|
|
12324
12638
|
return report;
|
|
12325
12639
|
}
|
|
12326
12640
|
function formatChironEnvReport(report, output = "table") {
|
|
12327
|
-
if (output !== "table") return
|
|
12641
|
+
if (output !== "table") return formatObject27(report, { format: output });
|
|
12328
12642
|
const lines = [
|
|
12329
12643
|
report.action === "list" ? `\u9879\u76EE\u73AF\u5883\uFF1A${report.path}` : `\u5DF2\u5199\u5165\uFF1A${report.path}`,
|
|
12330
12644
|
formatTable(report.environments.map((env2) => ({
|
|
@@ -12359,11 +12673,11 @@ import { accessSync, constants, readdirSync as readdirSync3 } from "fs";
|
|
|
12359
12673
|
import fs12 from "fs/promises";
|
|
12360
12674
|
import os5 from "os";
|
|
12361
12675
|
import path14 from "path";
|
|
12362
|
-
import { CliError as
|
|
12676
|
+
import { CliError as CliError31, CliErrorCode as CliErrorCode33, formatObject as formatObject28, HcmClient as HcmClient25, loadEnv as loadEnv6 } from "@hcmai/sdk";
|
|
12363
12677
|
import { createRequire } from "module";
|
|
12364
12678
|
|
|
12365
12679
|
// src/commands/chiron-page-cdp.ts
|
|
12366
|
-
import { CliError as
|
|
12680
|
+
import { CliError as CliError29, CliErrorCode as CliErrorCode31 } from "@hcmai/sdk";
|
|
12367
12681
|
|
|
12368
12682
|
// src/commands/chiron-page-shared.ts
|
|
12369
12683
|
function redactTicket(text) {
|
|
@@ -12399,14 +12713,14 @@ function normalizeCdpEndpoint(raw) {
|
|
|
12399
12713
|
try {
|
|
12400
12714
|
url = new URL(candidate);
|
|
12401
12715
|
} catch {
|
|
12402
|
-
throw new
|
|
12716
|
+
throw new CliError29({ code: CliErrorCode31.INVALID_ARGUMENT, message: `--cdp \u8981\u5199\u6210 http://\u4E3B\u673A:\u7AEF\u53E3\uFF08Chrome \u7684 --remote-debugging-port\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
|
|
12403
12717
|
}
|
|
12404
12718
|
const protocol = url.protocol === "wss:" ? "https:" : url.protocol === "ws:" ? "http:" : url.protocol;
|
|
12405
12719
|
if (protocol !== "http:" && protocol !== "https:") {
|
|
12406
|
-
throw new
|
|
12720
|
+
throw new CliError29({ code: CliErrorCode31.INVALID_ARGUMENT, message: `--cdp \u53EA\u8BA4 http(s) \u6216 ws(s) \u7AEF\u70B9\uFF0C\u6536\u5230\u7684\u662F ${text}` });
|
|
12407
12721
|
}
|
|
12408
12722
|
if (!url.port) {
|
|
12409
|
-
throw new
|
|
12723
|
+
throw new CliError29({ code: CliErrorCode31.INVALID_ARGUMENT, message: `--cdp \u8981\u5E26\u7AEF\u53E3\uFF08Chrome \u542F\u52A8\u65F6 --remote-debugging-port=<\u7AEF\u53E3> \u7684\u90A3\u4E2A\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
|
|
12410
12724
|
}
|
|
12411
12725
|
return `${protocol}//${url.hostname}:${url.port}`;
|
|
12412
12726
|
}
|
|
@@ -12503,8 +12817,8 @@ async function captureViaCdp(input, io) {
|
|
|
12503
12817
|
const browser = version?.Browser ? String(version.Browser) : `attached ${input.endpoint}`;
|
|
12504
12818
|
const target = await io.fetchJson(`${input.endpoint}/json/new?about:blank`, "PUT");
|
|
12505
12819
|
if (!target?.id || !target.webSocketDebuggerUrl) {
|
|
12506
|
-
throw new
|
|
12507
|
-
code:
|
|
12820
|
+
throw new CliError29({
|
|
12821
|
+
code: CliErrorCode31.SERVER_ERROR,
|
|
12508
12822
|
message: `${input.endpoint}/json/new \u6CA1\u6709\u7ED9\u51FA\u6807\u7B7E\u9875\uFF08id / webSocketDebuggerUrl \u7F3A\u5931\uFF09`,
|
|
12509
12823
|
context: { nextStep: "\u786E\u8BA4 Chrome \u662F\u5E26 --remote-debugging-port \u8D77\u7684\uFF0C\u4E14 --cdp \u6307\u5230\u7684\u662F\u5B83" }
|
|
12510
12824
|
});
|
|
@@ -12534,7 +12848,7 @@ async function captureViaCdp(input, io) {
|
|
|
12534
12848
|
});
|
|
12535
12849
|
if (r.exceptionDetails) {
|
|
12536
12850
|
const why = r.exceptionDetails.exception?.description ?? r.exceptionDetails.text ?? "unknown";
|
|
12537
|
-
throw new
|
|
12851
|
+
throw new CliError29({ code: CliErrorCode31.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why.split("\n")[0] ?? why)}` });
|
|
12538
12852
|
}
|
|
12539
12853
|
evalResult = r.result && "value" in r.result ? toPlainJson(r.result.value) : toPlainJson(r.result?.description);
|
|
12540
12854
|
}
|
|
@@ -12545,7 +12859,7 @@ async function captureViaCdp(input, io) {
|
|
|
12545
12859
|
const dom = typeof domReply.result?.value === "string" ? domReply.result.value : "";
|
|
12546
12860
|
const shot = await session.send("Page.captureScreenshot", { format: "png" });
|
|
12547
12861
|
if (!shot.data) {
|
|
12548
|
-
throw new
|
|
12862
|
+
throw new CliError29({ code: CliErrorCode31.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
|
|
12549
12863
|
}
|
|
12550
12864
|
await io.writeFile(input.screenshot, Buffer.from(shot.data, "base64"));
|
|
12551
12865
|
return { dom, browser, evalResult, navigated, minted };
|
|
@@ -12567,7 +12881,7 @@ var defaultCdpIo = {
|
|
|
12567
12881
|
openSocket: (wsUrl) => new Promise((resolve3, reject) => {
|
|
12568
12882
|
const Ctor = globalThis.WebSocket;
|
|
12569
12883
|
if (!Ctor) {
|
|
12570
|
-
reject(new
|
|
12884
|
+
reject(new CliError29({ code: CliErrorCode31.SERVER_ERROR, message: "\u8FD9\u4E2A Node \u6CA1\u6709\u5168\u5C40 WebSocket\uFF08\u9700\u8981 Node \u2265 22.4\uFF1B22.0\u201322.3 \u8981\u52A0 --experimental-websocket\uFF09" }));
|
|
12571
12885
|
return;
|
|
12572
12886
|
}
|
|
12573
12887
|
const ws = new Ctor(wsUrl);
|
|
@@ -12590,7 +12904,7 @@ var defaultCdpIo = {
|
|
|
12590
12904
|
|
|
12591
12905
|
// src/commands/chiron-page-playwright.ts
|
|
12592
12906
|
import path13 from "path";
|
|
12593
|
-
import { CliError as
|
|
12907
|
+
import { CliError as CliError30, CliErrorCode as CliErrorCode32 } from "@hcmai/sdk";
|
|
12594
12908
|
function playwrightCacheRoot(probe) {
|
|
12595
12909
|
const override = probe.env.PLAYWRIGHT_BROWSERS_PATH?.trim();
|
|
12596
12910
|
if (override === "0" && probe.packageRoot) return path13.join(probe.packageRoot, ".local-browsers");
|
|
@@ -12633,8 +12947,8 @@ function discoverPlaywrightBrowser(probe) {
|
|
|
12633
12947
|
const explicit = probe.env.HCM_PLAYWRIGHT_EXECUTABLE?.trim();
|
|
12634
12948
|
if (explicit) {
|
|
12635
12949
|
if (probe.executable(explicit)) return { executablePath: explicit, kind: "explicit", from: "HCM_PLAYWRIGHT_EXECUTABLE" };
|
|
12636
|
-
throw new
|
|
12637
|
-
code:
|
|
12950
|
+
throw new CliError30({
|
|
12951
|
+
code: CliErrorCode32.INVALID_ARGUMENT,
|
|
12638
12952
|
message: `HCM_PLAYWRIGHT_EXECUTABLE \u6307\u7684\u6587\u4EF6\u4E0D\u53EF\u6267\u884C\uFF1A${explicit}`,
|
|
12639
12953
|
context: { nextStep: "\u6307\u5230 Playwright \u88C5\u7684 chrome-headless-shell / chrome \u4E8C\u8FDB\u5236\uFF0C\u6216\u53BB\u6389\u8FD9\u4E2A\u53D8\u91CF\u8BA9 CLI \u81EA\u5DF1\u627E" }
|
|
12640
12954
|
});
|
|
@@ -12676,8 +12990,8 @@ async function captureViaPlaywright(input) {
|
|
|
12676
12990
|
}
|
|
12677
12991
|
}
|
|
12678
12992
|
if (!browser) {
|
|
12679
|
-
throw new
|
|
12680
|
-
code:
|
|
12993
|
+
throw new CliError30({
|
|
12994
|
+
code: CliErrorCode32.SERVER_ERROR,
|
|
12681
12995
|
message: `Playwright \u8D77\u4E0D\u4E86\u6D4F\u89C8\u5668\uFF1A${failures.join("\uFF1B")}`,
|
|
12682
12996
|
context: {
|
|
12683
12997
|
nextStep: "\u88C5\u4E00\u4EFD Playwright \u7684 Chromium\uFF1Anpx playwright install chromium-headless-shell\uFF08\u6216 chromium\uFF09\uFF1B\u5DF2\u7ECF\u88C5\u4E86\u4F46\u4E0D\u5728\u7F3A\u7701\u7F13\u5B58\u76EE\u5F55\u5C31 export PLAYWRIGHT_BROWSERS_PATH=<\u76EE\u5F55> \u6216 HCM_PLAYWRIGHT_EXECUTABLE=<\u4E8C\u8FDB\u5236>\uFF1B\u6C99\u7BB1\u8FDE headless shell \u90FD\u8D77\u4E0D\u4E86\u65F6\uFF0C\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u5E76\u7528 --cdp \u8FDE"
|
|
@@ -12697,7 +13011,7 @@ async function captureViaPlaywright(input) {
|
|
|
12697
13011
|
evalResult = toPlainJson(await page.evaluate(wrapEvalBody(input.evalJs)));
|
|
12698
13012
|
} catch (e) {
|
|
12699
13013
|
const why = (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "";
|
|
12700
|
-
throw new
|
|
13014
|
+
throw new CliError30({ code: CliErrorCode32.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
|
|
12701
13015
|
}
|
|
12702
13016
|
}
|
|
12703
13017
|
const dom = await page.content();
|
|
@@ -12721,13 +13035,13 @@ function judgePageContent(input) {
|
|
|
12721
13035
|
function parseViewport(size) {
|
|
12722
13036
|
const m = /^(\d+)x(\d+)$/.exec(size.trim());
|
|
12723
13037
|
if (!m) {
|
|
12724
|
-
throw new
|
|
13038
|
+
throw new CliError31({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--size \u8981\u5199\u6210 <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900\uFF0C\u6536\u5230\u7684\u662F ${size}` });
|
|
12725
13039
|
}
|
|
12726
13040
|
const width = Number(m[1]);
|
|
12727
13041
|
const height = Number(m[2]);
|
|
12728
13042
|
if (width < VIEWPORT_MIN.width || width > VIEWPORT_MAX.width || height < VIEWPORT_MIN.height || height > VIEWPORT_MAX.height) {
|
|
12729
|
-
throw new
|
|
12730
|
-
code:
|
|
13043
|
+
throw new CliError31({
|
|
13044
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12731
13045
|
message: `--size \u8D85\u51FA\u8303\u56F4\uFF1A\u5BBD ${VIEWPORT_MIN.width}..${VIEWPORT_MAX.width}\u3001\u9AD8 ${VIEWPORT_MIN.height}..${VIEWPORT_MAX.height}\uFF0C\u6536\u5230\u7684\u662F ${size}`
|
|
12732
13046
|
});
|
|
12733
13047
|
}
|
|
@@ -12737,23 +13051,23 @@ function parseWaitMs(raw) {
|
|
|
12737
13051
|
if (raw === void 0) return 1e4;
|
|
12738
13052
|
const value = typeof raw === "number" ? raw : Number(raw);
|
|
12739
13053
|
if (!Number.isInteger(value) || value < 0 || value > WAIT_MS_MAX) {
|
|
12740
|
-
throw new
|
|
13054
|
+
throw new CliError31({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--wait-ms \u8981\u662F 0..${WAIT_MS_MAX} \u7684\u6574\u6570\uFF0C\u6536\u5230\u7684\u662F ${raw}` });
|
|
12741
13055
|
}
|
|
12742
13056
|
return value;
|
|
12743
13057
|
}
|
|
12744
13058
|
function resolveEvidenceTarget(projectRoot, out) {
|
|
12745
13059
|
if (!out?.trim()) {
|
|
12746
|
-
throw new
|
|
13060
|
+
throw new CliError31({ code: CliErrorCode33.MISSING_FLAG, message: `\u8981\u4F20 --out <${EVIDENCE_DIR}/\u2026/\u622A\u56FE.png>\uFF1A\u622A\u56FE\u843D\u5728\u54EA\u513F\u5FC5\u987B\u662F\u4F60\u5B9A\u7684\uFF0C\u4E0D\u7531\u547D\u4EE4\u731C` });
|
|
12747
13061
|
}
|
|
12748
13062
|
if (!out.endsWith(".png")) {
|
|
12749
|
-
throw new
|
|
13063
|
+
throw new CliError31({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
|
|
12750
13064
|
}
|
|
12751
13065
|
const root = path14.resolve(projectRoot);
|
|
12752
13066
|
const evidenceRoot = path14.join(root, EVIDENCE_DIR);
|
|
12753
13067
|
const absolute = path14.resolve(root, out);
|
|
12754
13068
|
if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path14.sep)) {
|
|
12755
|
-
throw new
|
|
12756
|
-
code:
|
|
13069
|
+
throw new CliError31({
|
|
13070
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12757
13071
|
message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
|
|
12758
13072
|
});
|
|
12759
13073
|
}
|
|
@@ -12801,8 +13115,8 @@ async function assertInsideEvidence(deps, evidenceRoot, absolute) {
|
|
|
12801
13115
|
const canonicalParent = await deps.realpath(path14.dirname(absolute));
|
|
12802
13116
|
if (canonicalRoot === null || canonicalParent === null) return;
|
|
12803
13117
|
if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path14.sep)) {
|
|
12804
|
-
throw new
|
|
12805
|
-
code:
|
|
13118
|
+
throw new CliError31({
|
|
13119
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12806
13120
|
message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
|
|
12807
13121
|
});
|
|
12808
13122
|
}
|
|
@@ -12811,8 +13125,8 @@ async function runChironPage(target, args, deps) {
|
|
|
12811
13125
|
const sitePath = normalizeTarget(target);
|
|
12812
13126
|
const expect = (args.expectText ?? []).filter((t) => t.trim().length > 0);
|
|
12813
13127
|
if (expect.length === 0) {
|
|
12814
|
-
throw new
|
|
12815
|
-
code:
|
|
13128
|
+
throw new CliError31({
|
|
13129
|
+
code: CliErrorCode33.MISSING_FLAG,
|
|
12816
13130
|
message: "\u81F3\u5C11\u8981\u4F20\u4E00\u6761 --expect-text\uFF08\u9875\u9762\u4E0A\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C\uFF09\u3002\u53EA\u5224\u300C\u622A\u51FA\u56FE\u4E86\u300D\u4E0D\u7B97\u9A8C\u6536\uFF1A\u767B\u5F55\u9875\u3001\u62A5\u9519\u9875\u3001\u767D\u5C4F\u90FD\u80FD\u622A\u51FA\u56FE\u3002"
|
|
12817
13131
|
});
|
|
12818
13132
|
}
|
|
@@ -12822,8 +13136,8 @@ async function runChironPage(target, args, deps) {
|
|
|
12822
13136
|
const root = path14.resolve(args.project ?? ".");
|
|
12823
13137
|
const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
|
|
12824
13138
|
if (await deps.present(absolute)) {
|
|
12825
|
-
throw new
|
|
12826
|
-
code:
|
|
13139
|
+
throw new CliError31({
|
|
13140
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12827
13141
|
message: `\u622A\u56FE\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8986\u76D6\uFF1A${absolute}\u3002\u6362\u4E2A --out\uFF0C\u6216\u5148\u628A\u65E7\u8BC1\u636E\u632A\u8D70\u3002`
|
|
12828
13142
|
});
|
|
12829
13143
|
}
|
|
@@ -12835,8 +13149,8 @@ async function runChironPage(target, args, deps) {
|
|
|
12835
13149
|
const playwrightBrowser = endpoint || forceSpawn ? null : deps.findPlaywrightBrowser();
|
|
12836
13150
|
const usePlaywright = !endpoint && !forceSpawn && (playwrightBrowser !== null || evalJs !== void 0);
|
|
12837
13151
|
if (evalJs && !endpoint && !usePlaywright) {
|
|
12838
|
-
throw new
|
|
12839
|
-
code:
|
|
13152
|
+
throw new CliError31({
|
|
13153
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12840
13154
|
message: "--eval \u9700\u8981 Playwright \u6216 --cdp\uFF1A\u8001\u7684 spawn \u8DEF\u5F84\u53EA\u4F1A --dump-dom\uFF0C\u585E\u4E0D\u8FDB\u811A\u672C\u3002",
|
|
12841
13155
|
context: { nextStep: "npx playwright install chromium-headless-shell\uFF0C\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
|
|
12842
13156
|
});
|
|
@@ -12854,10 +13168,10 @@ async function runChironPage(target, args, deps) {
|
|
|
12854
13168
|
try {
|
|
12855
13169
|
captured = endpoint ? await deps.captureAttached({ endpoint, viewport, waitMs, evalJs, screenshot: absolute, mintUrl: mint }) : await deps.capturePlaywright({ viewport, waitMs, evalJs, screenshot: absolute, browser: playwrightBrowser, mintUrl: mint });
|
|
12856
13170
|
} catch (e) {
|
|
12857
|
-
if (e instanceof
|
|
13171
|
+
if (e instanceof CliError31) throw new CliError31({ code: e.code, message: redactTicket(e.message), context: e.context });
|
|
12858
13172
|
const where = endpoint ? `\u8FDE\u5230 ${endpoint} \u7684 Chrome` : "Playwright \u8D77\u7684\u6D4F\u89C8\u5668";
|
|
12859
|
-
throw new
|
|
12860
|
-
code:
|
|
13173
|
+
throw new CliError31({
|
|
13174
|
+
code: CliErrorCode33.SERVER_ERROR,
|
|
12861
13175
|
message: `${where}\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(e instanceof Error ? e.message : String(e))}`,
|
|
12862
13176
|
context: {
|
|
12863
13177
|
nextStep: endpoint ? `\u6838\u4E00\u773C ${endpoint}/json/version \u80FD\u4E0D\u80FD\u6253\u5F00\uFF1BChrome \u8981\u5E26 --remote-debugging-port \u8D77\uFF0C\u4E14\u6C99\u7BB1\u653E\u884C\u4E86\u8FD9\u4E2A\u7AEF\u53E3` : "npx playwright install chromium-headless-shell \u540E\u91CD\u8DD1\uFF1B\u6216 HCM_CHIRON_PAGE_DRIVER=spawn \u8D70\u8001\u8DEF\u5F84\u5BF9\u7167"
|
|
@@ -12873,8 +13187,8 @@ async function runChironPage(target, args, deps) {
|
|
|
12873
13187
|
mode = "spawn";
|
|
12874
13188
|
const browser = deps.findBrowser();
|
|
12875
13189
|
if (!browser) {
|
|
12876
|
-
throw new
|
|
12877
|
-
code:
|
|
13190
|
+
throw new CliError31({
|
|
13191
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12878
13192
|
message: "\u672C\u673A\u627E\u4E0D\u5230 Playwright \u7684 Chromium\uFF0C\u4E5F\u627E\u4E0D\u5230 Chrome/Chromium\uFF0C\u622A\u4E0D\u4E86\u56FE\u3002",
|
|
12879
13193
|
context: { nextStep: "npx playwright install chromium-headless-shell\uFF08\u6C99\u7BB1\u91CC\u4E5F\u80FD\u8DD1\uFF09\uFF1B\u6216\u88C5\u4E00\u4E2A Chrome / HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84\uFF1B\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
|
|
12880
13194
|
});
|
|
@@ -12882,8 +13196,8 @@ async function runChironPage(target, args, deps) {
|
|
|
12882
13196
|
minted = await mint();
|
|
12883
13197
|
const result = deps.capture({ browser, argv: chromeArgv({ viewport, waitMs, screenshot: absolute, url: minted.url, isRoot: process.getuid?.() === 0 }) });
|
|
12884
13198
|
if (!result.ok) {
|
|
12885
|
-
throw new
|
|
12886
|
-
code:
|
|
13199
|
+
throw new CliError31({
|
|
13200
|
+
code: CliErrorCode33.SERVER_ERROR,
|
|
12887
13201
|
message: `\u6D4F\u89C8\u5668\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(result.stderr.trim().split("\n").slice(-1)[0] ?? "\u65E0\u8F93\u51FA")}`,
|
|
12888
13202
|
context: { nextStep: spawnFailureNextStep(browser, result, deps.platform) }
|
|
12889
13203
|
});
|
|
@@ -12893,7 +13207,7 @@ async function runChironPage(target, args, deps) {
|
|
|
12893
13207
|
}
|
|
12894
13208
|
const bytes = await deps.present(absolute) ? await deps.sizeOf(absolute) : 0;
|
|
12895
13209
|
if (bytes === 0) {
|
|
12896
|
-
throw new
|
|
13210
|
+
throw new CliError31({ code: CliErrorCode33.SERVER_ERROR, message: `\u6D4F\u89C8\u5668\u6CA1\u5199\u51FA\u975E\u7A7A PNG\uFF1A${absolute}` });
|
|
12897
13211
|
}
|
|
12898
13212
|
const verdict = judgePageContent({ dom, expect, reject });
|
|
12899
13213
|
return {
|
|
@@ -12956,13 +13270,13 @@ var defaultChironPageDeps = {
|
|
|
12956
13270
|
const envCfg = await loadEnv6(ctx.env);
|
|
12957
13271
|
const frontend = ctx.frontend ?? envCfg.frontend;
|
|
12958
13272
|
if (!frontend?.trim()) {
|
|
12959
|
-
throw new
|
|
12960
|
-
code:
|
|
13273
|
+
throw new CliError31({
|
|
13274
|
+
code: CliErrorCode33.INVALID_ARGUMENT,
|
|
12961
13275
|
message: `env '${ctx.env}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002`,
|
|
12962
13276
|
context: { nextStep: `hcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${ctx.env}` }
|
|
12963
13277
|
});
|
|
12964
13278
|
}
|
|
12965
|
-
const client3 =
|
|
13279
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
12966
13280
|
const { ticket } = await mintBrowserTicket(client3, ctx.env)();
|
|
12967
13281
|
return { url: buildBrowserLoginUrl(frontend, ticket, sitePath), environment: ctx.env, identity: ctx.identity ?? null };
|
|
12968
13282
|
},
|
|
@@ -13024,7 +13338,7 @@ async function chironPageCommand(target, args, deps = defaultChironPageDeps) {
|
|
|
13024
13338
|
try {
|
|
13025
13339
|
const receipt = await runChironPage(target, args, deps);
|
|
13026
13340
|
const fmt = args.output ?? "table";
|
|
13027
|
-
if (fmt === "json" || fmt === "yaml") process.stdout.write(
|
|
13341
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject28(receipt, { format: fmt }) + "\n");
|
|
13028
13342
|
else process.stdout.write(renderChironPage(receipt) + "\n");
|
|
13029
13343
|
process.exitCode = receipt.ok ? 0 : 3;
|
|
13030
13344
|
} catch (e) {
|
|
@@ -13039,11 +13353,11 @@ import { randomUUID } from "crypto";
|
|
|
13039
13353
|
import { promises as fs13 } from "fs";
|
|
13040
13354
|
import path15 from "path";
|
|
13041
13355
|
import yaml2 from "js-yaml";
|
|
13042
|
-
import { formatObject as
|
|
13356
|
+
import { formatObject as formatObject29 } from "@hcmai/sdk";
|
|
13043
13357
|
|
|
13044
13358
|
// src/commands/delivery-action-policy.ts
|
|
13045
13359
|
init_auth_guard();
|
|
13046
|
-
import { HcmClient as
|
|
13360
|
+
import { HcmClient as HcmClient26, classifyEffect } from "@hcmai/sdk";
|
|
13047
13361
|
|
|
13048
13362
|
// src/commands/delivery.ts
|
|
13049
13363
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -13363,6 +13677,12 @@ function classify(argv, actionResolution) {
|
|
|
13363
13677
|
if (name === "chat") {
|
|
13364
13678
|
return forbidden("agent-autonomy", "\u987E\u95EE\u63D2\u4EF6\u4E0D\u901A\u8FC7\u5D4C\u5957\u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u6269\u5927\u81EA\u6CBB\u6267\u884C\u9762\u3002");
|
|
13365
13679
|
}
|
|
13680
|
+
if (name === "interactions") {
|
|
13681
|
+
return forbidden(
|
|
13682
|
+
"agent-autonomy",
|
|
13683
|
+
"\u987E\u95EE\u63D2\u4EF6\u4E0D\u4EE3\u66FF\u7528\u6237\u6279\u51C6\u6570\u5B57\u5458\u5DE5\u7684\u6682\u505C\uFF1A\u90A3\u662F\u5728\u66FF\u5B83\u653E\u884C\u4E00\u6B21\u5199\u5165\u3002"
|
|
13684
|
+
);
|
|
13685
|
+
}
|
|
13366
13686
|
return forbidden(
|
|
13367
13687
|
"unknown-command",
|
|
13368
13688
|
`\u672A\u77E5\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\uFF1A\u89E3\u6790\u5230\u7684\u547D\u4EE4\u662F ${name || "(\u7A7A)"}` + (subcommand ? ` ${subcommand}` : "") + "\u3002next_step=\u7528 `hcm --help` \u6838\u5BF9\u547D\u4EE4\u540D\uFF1B\u82E5\u4F60\u786E\u4FE1\u8FD9\u6761\u547D\u4EE4\u5B58\u5728\uFF0C\u5148\u8DD1 `hcm upgrade` \u770B CLI \u662F\u4E0D\u662F\u65E7\u7248\uFF08\u98CE\u63A7\u8868\u968F CLI \u53D1\u5E03\u66F4\u65B0\uFF09"
|
|
@@ -13558,7 +13878,7 @@ async function resolveCoreAction(request) {
|
|
|
13558
13878
|
as: request.identity,
|
|
13559
13879
|
profile: request.profile
|
|
13560
13880
|
});
|
|
13561
|
-
const description = await
|
|
13881
|
+
const description = await HcmClient26.fromAuthContext(auth).describe(request.model);
|
|
13562
13882
|
const named = description.actions.filter((action) => action.name === request.action);
|
|
13563
13883
|
if (named.length === 0) {
|
|
13564
13884
|
const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
|
|
@@ -14000,7 +14320,7 @@ async function chironTestCommand(target, args, deps) {
|
|
|
14000
14320
|
}
|
|
14001
14321
|
const fmt = args.output ?? "table";
|
|
14002
14322
|
if (fmt === "json" || fmt === "yaml") {
|
|
14003
|
-
process.stdout.write(
|
|
14323
|
+
process.stdout.write(formatObject29({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
|
|
14004
14324
|
} else {
|
|
14005
14325
|
for (const c of report) {
|
|
14006
14326
|
process.stdout.write(`
|
|
@@ -14029,11 +14349,11 @@ ${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4
|
|
|
14029
14349
|
init_auth_guard();
|
|
14030
14350
|
init_exit();
|
|
14031
14351
|
import {
|
|
14032
|
-
HcmClient as
|
|
14352
|
+
HcmClient as HcmClient27,
|
|
14033
14353
|
ReconLayout,
|
|
14034
14354
|
ROUND_EXIT_CODES,
|
|
14035
14355
|
computeReconSourceKey,
|
|
14036
|
-
formatObject as
|
|
14356
|
+
formatObject as formatObject30,
|
|
14037
14357
|
fromAxiosError as fromAxiosError22,
|
|
14038
14358
|
httpProbe as httpProbe3,
|
|
14039
14359
|
inspectRound,
|
|
@@ -14044,7 +14364,7 @@ var DEFAULT_CAPABILITIES = "default";
|
|
|
14044
14364
|
async function deliveryReconCommand(args) {
|
|
14045
14365
|
try {
|
|
14046
14366
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
14047
|
-
const client3 =
|
|
14367
|
+
const client3 = HcmClient27.fromAuthContext(ctx);
|
|
14048
14368
|
const probe = httpProbe3(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
|
|
14049
14369
|
const sourceKey = await computeReconSourceKey(probe);
|
|
14050
14370
|
const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
|
|
@@ -14053,7 +14373,7 @@ async function deliveryReconCommand(args) {
|
|
|
14053
14373
|
onlyModel: args.model ?? null,
|
|
14054
14374
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
14055
14375
|
});
|
|
14056
|
-
process.stdout.write(
|
|
14376
|
+
process.stdout.write(formatObject30(summary, { format: args.output ?? "json" }) + "\n");
|
|
14057
14377
|
} catch (e) {
|
|
14058
14378
|
const err = e;
|
|
14059
14379
|
if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
|
|
@@ -14067,7 +14387,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
14067
14387
|
const result = inspectRound(args.dir ?? ".");
|
|
14068
14388
|
const fmt = args.output ?? "json";
|
|
14069
14389
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
14070
|
-
process.stdout.write(
|
|
14390
|
+
process.stdout.write(formatObject30(result, { format: fmt }) + "\n");
|
|
14071
14391
|
code = ROUND_EXIT_CODES[result.state];
|
|
14072
14392
|
} catch (e) {
|
|
14073
14393
|
exitWithError(e);
|
|
@@ -14087,7 +14407,7 @@ import {
|
|
|
14087
14407
|
DRY_RUN_TAIL,
|
|
14088
14408
|
DriftDetected,
|
|
14089
14409
|
FORCE_STALE_FLAG,
|
|
14090
|
-
HcmClient as
|
|
14410
|
+
HcmClient as HcmClient28,
|
|
14091
14411
|
fetchReconIdentity as fetchReconIdentity3,
|
|
14092
14412
|
INIT_EXIT_CODES,
|
|
14093
14413
|
JOURNAL_STOP_KINDS,
|
|
@@ -14227,7 +14547,7 @@ async function authOrSignpost(args, cmd) {
|
|
|
14227
14547
|
}
|
|
14228
14548
|
async function deliverySeedPlanCommand(args) {
|
|
14229
14549
|
const ctx = await authOrSignpost(args, "plan");
|
|
14230
|
-
const client3 =
|
|
14550
|
+
const client3 = HcmClient28.fromAuthContext(ctx);
|
|
14231
14551
|
process.exitCode = await runSeedPlan(args, seedClient(client3, ctx));
|
|
14232
14552
|
}
|
|
14233
14553
|
function seedClient(client3, ctx) {
|
|
@@ -14401,7 +14721,7 @@ async function runSeedApply(args, client3) {
|
|
|
14401
14721
|
}
|
|
14402
14722
|
async function deliverySeedApplyCommand(args) {
|
|
14403
14723
|
const ctx = await authOrSignpost(args, "apply");
|
|
14404
|
-
const client3 =
|
|
14724
|
+
const client3 = HcmClient28.fromAuthContext(ctx);
|
|
14405
14725
|
process.exitCode = await runSeedApply(args, seedClient(client3, ctx));
|
|
14406
14726
|
}
|
|
14407
14727
|
async function runSeedVerify(args, client3) {
|
|
@@ -14425,7 +14745,7 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
14425
14745
|
return;
|
|
14426
14746
|
}
|
|
14427
14747
|
const ctx = await authOrSignpost(args, "verify");
|
|
14428
|
-
const client3 =
|
|
14748
|
+
const client3 = HcmClient28.fromAuthContext(ctx);
|
|
14429
14749
|
process.exitCode = await runSeedVerify(args, await seedVerifyClient(client3, ctx));
|
|
14430
14750
|
}
|
|
14431
14751
|
|
|
@@ -14540,7 +14860,7 @@ import {
|
|
|
14540
14860
|
CHANGE_STATES,
|
|
14541
14861
|
CHANGE_UNKNOWN,
|
|
14542
14862
|
CODE_WORDS,
|
|
14543
|
-
HcmClient as
|
|
14863
|
+
HcmClient as HcmClient29,
|
|
14544
14864
|
INIT_EXIT_CODES as INIT_EXIT_CODES3,
|
|
14545
14865
|
META_WRITE_STEPS,
|
|
14546
14866
|
META_VERIFY_STEPS,
|
|
@@ -14768,7 +15088,7 @@ function lowerCaseHeaders2(headers) {
|
|
|
14768
15088
|
}
|
|
14769
15089
|
async function deliveryMetaCommand(args) {
|
|
14770
15090
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
14771
|
-
const client3 =
|
|
15091
|
+
const client3 = HcmClient29.fromAuthContext(ctx);
|
|
14772
15092
|
process.exitCode = await runDeliveryMeta(
|
|
14773
15093
|
{ ...args, tenant: args.tenant ?? String(ctx.tenantId ?? "") },
|
|
14774
15094
|
metaClient(client3, ctx)
|
|
@@ -14780,7 +15100,7 @@ init_auth_guard();
|
|
|
14780
15100
|
init_exit();
|
|
14781
15101
|
import {
|
|
14782
15102
|
computeReconSourceKey as computeReconSourceKey2,
|
|
14783
|
-
HcmClient as
|
|
15103
|
+
HcmClient as HcmClient30,
|
|
14784
15104
|
httpProbe as httpProbe4,
|
|
14785
15105
|
ReconLayout as ReconLayout2,
|
|
14786
15106
|
runTriageRound
|
|
@@ -14836,7 +15156,7 @@ async function runTriage(args) {
|
|
|
14836
15156
|
return premise4(e instanceof Error ? e.message : String(e), REQUESTS_SHAPE);
|
|
14837
15157
|
}
|
|
14838
15158
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
14839
|
-
const client3 =
|
|
15159
|
+
const client3 = HcmClient30.fromAuthContext(ctx);
|
|
14840
15160
|
const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES3);
|
|
14841
15161
|
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
|
|
14842
15162
|
const result = await runTriageRound(probe, artifactsDir, entriesIn);
|
|
@@ -14865,25 +15185,25 @@ async function deliveryTriageCommand(args) {
|
|
|
14865
15185
|
init_auth_guard();
|
|
14866
15186
|
init_exit();
|
|
14867
15187
|
import {
|
|
14868
|
-
HcmClient as
|
|
15188
|
+
HcmClient as HcmClient31,
|
|
14869
15189
|
adminResetPassword,
|
|
14870
|
-
formatObject as
|
|
15190
|
+
formatObject as formatObject31,
|
|
14871
15191
|
fromAxiosError as fromAxiosError23,
|
|
14872
|
-
CliError as
|
|
14873
|
-
CliErrorCode as
|
|
15192
|
+
CliError as CliError32,
|
|
15193
|
+
CliErrorCode as CliErrorCode34
|
|
14874
15194
|
} from "@hcmai/sdk";
|
|
14875
15195
|
function buildAdminResetPasswordRequest(args, password) {
|
|
14876
15196
|
const hasId = Boolean(args.id);
|
|
14877
15197
|
const hasUsername = Boolean(args.username);
|
|
14878
15198
|
if (hasId === hasUsername) {
|
|
14879
|
-
throw new
|
|
14880
|
-
code:
|
|
15199
|
+
throw new CliError32({
|
|
15200
|
+
code: CliErrorCode34.INVALID_ARGUMENT,
|
|
14881
15201
|
message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
|
|
14882
15202
|
});
|
|
14883
15203
|
}
|
|
14884
15204
|
if (!password) {
|
|
14885
|
-
throw new
|
|
14886
|
-
code:
|
|
15205
|
+
throw new CliError32({
|
|
15206
|
+
code: CliErrorCode34.INVALID_ARGUMENT,
|
|
14887
15207
|
message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
|
|
14888
15208
|
});
|
|
14889
15209
|
}
|
|
@@ -14899,9 +15219,9 @@ async function userResetPasswordCommand(args) {
|
|
|
14899
15219
|
try {
|
|
14900
15220
|
const password = args.passwordStdin ? await readSecretFromStdin() : await promptPasswordTwice();
|
|
14901
15221
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
14902
|
-
const client3 =
|
|
15222
|
+
const client3 = HcmClient31.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
14903
15223
|
const result = await adminResetPassword(client3.raw(), request);
|
|
14904
|
-
process.stdout.write(
|
|
15224
|
+
process.stdout.write(formatObject31(result, { format: args.output ?? "json" }) + "\n");
|
|
14905
15225
|
} catch (cause) {
|
|
14906
15226
|
const err = cause;
|
|
14907
15227
|
if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
|
|
@@ -14912,8 +15232,8 @@ async function promptPasswordTwice() {
|
|
|
14912
15232
|
const password = await promptSecret("\u65B0\u5BC6\u7801: ");
|
|
14913
15233
|
const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
|
|
14914
15234
|
if (password !== confirmation) {
|
|
14915
|
-
throw new
|
|
14916
|
-
code:
|
|
15235
|
+
throw new CliError32({
|
|
15236
|
+
code: CliErrorCode34.INVALID_ARGUMENT,
|
|
14917
15237
|
message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
|
|
14918
15238
|
});
|
|
14919
15239
|
}
|
|
@@ -14924,19 +15244,19 @@ async function promptPasswordTwice() {
|
|
|
14924
15244
|
init_exit();
|
|
14925
15245
|
init_auth_guard();
|
|
14926
15246
|
import {
|
|
14927
|
-
HcmClient as
|
|
14928
|
-
formatObject as
|
|
15247
|
+
HcmClient as HcmClient32,
|
|
15248
|
+
formatObject as formatObject32,
|
|
14929
15249
|
fromAxiosError as fromAxiosError24
|
|
14930
15250
|
} from "@hcmai/sdk";
|
|
14931
15251
|
async function modelsCommand(keyword, args) {
|
|
14932
15252
|
try {
|
|
14933
|
-
const client3 =
|
|
15253
|
+
const client3 = HcmClient32.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
14934
15254
|
const all = await client3.listModels();
|
|
14935
15255
|
const needle = keyword?.trim().toLowerCase();
|
|
14936
15256
|
const rows2 = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
14937
15257
|
const fmt = args.output ?? "table";
|
|
14938
15258
|
if (fmt !== "table") {
|
|
14939
|
-
process.stdout.write(
|
|
15259
|
+
process.stdout.write(formatObject32({ total: rows2.length, models: rows2 }, { format: fmt }) + "\n");
|
|
14940
15260
|
process.exitCode = 0;
|
|
14941
15261
|
return;
|
|
14942
15262
|
}
|
|
@@ -15134,7 +15454,7 @@ program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6
|
|
|
15134
15454
|
).option("--sort <JSON>", `\u6392\u5E8F\u6761\u4EF6 JSON\uFF0C\u4F8B\u5982 '[{"field":"hireDate","direction":"desc"}]'`).option(
|
|
15135
15455
|
"--additions <JSON>",
|
|
15136
15456
|
`\u8DE8\u5173\u7CFB JOIN \u7684\u5BF9\u8C61\u6570\u7EC4 JSON\uFF0C\u4F8B\u5982 '[{"key":"employee","model":"Employee"}]'`
|
|
15137
|
-
).option("--fields <list>", "\u8FD4\u56DE\u5B57\u6BB5\u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09\uFF0C\u4F8B\u5982 name,code,email").option("--keyword <text>", "\u5168\u6587\u68C0\u7D22\u5173\u952E\u5B57").option("--limit <n>", "\u6BCF\u9875\u5927\u5C0F", "20").option("--offset <n>", "\u504F\u79FB\u91CF\uFF08\u6309 limit \u81EA\u52A8\u6362\u7B97 page\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((m, opts) => queryCommand(m, opts));
|
|
15457
|
+
).option("--fields <list>", "\u8FD4\u56DE\u5B57\u6BB5\u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09\uFF0C\u4F8B\u5982 name,code,email").option("--plugin <activation>", "\u5143\u6570\u636E\u63D2\u4EF6\u6FC0\u6D3B\u4E32\uFF0C\u4F8B\u5982 salaryByAssist:assistId=<uuid>").option("--keyword <text>", "\u5168\u6587\u68C0\u7D22\u5173\u952E\u5B57").option("--limit <n>", "\u6BCF\u9875\u5927\u5C0F", "20").option("--offset <n>", "\u504F\u79FB\u91CF\uFF08\u6309 limit \u81EA\u52A8\u6362\u7B97 page\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((m, opts) => queryCommand(m, opts));
|
|
15138
15458
|
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(
|
|
15139
15459
|
"--scope <scope>",
|
|
15140
15460
|
"\u5F3A\u5236 Action scope\uFF1Aclass | object\uFF08\u9ED8\u8BA4\uFF1A\u6709 --id \u4E3A object\uFF0C\u5426\u5219 class\uFF09"
|
|
@@ -15149,7 +15469,24 @@ program.command("create <Model>").description("\u521B\u5EFA\u4E00\u6761 Model \u
|
|
|
15149
15469
|
program.command("delete <Model>").description("\u5220\u9664\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF1B\u90E8\u5206 Model \u4F1A\u6267\u884C\u4E1A\u52A1\u64A4\u9500\uFF09").option("--id <id>", "\u76EE\u6807\u5B9E\u4F53 ID\uFF08\u5FC5\u586B\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((m, opts) => deleteCommand(m, opts));
|
|
15150
15470
|
program.command("import <path>").description("\u6CE8\u5165 DataPackage YAML \u6570\u636E\u96C6\uFF08\u76EE\u5F55\u6216\u5355\u6587\u4EF6\uFF0C\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09").option("--dry-run", "\u53EA\u8DD1\u5BA2\u6237\u7AEF\u9759\u6001\u6821\u9A8C\uFF0C\u4E0D\u843D\u5E93\uFF08\u89C1 spec \xA78 \u9650\u5236\uFF09").option("--update-only", "\u5DF2\u5B58\u5728\uFF08\u6309 key_field\uFF09\u5219 PUT \u66F4\u65B0\uFF0C\u5426\u5219 create").option("--on-error <mode>", "stop | continue\uFF08\u9ED8\u8BA4 continue\uFF09", "continue").option("--report <path>", "\u5199 JSON \u6CE8\u5165\u62A5\u544A\uFF08\u9010\u884C\u7ED3\u679C + key\u2192id \u6620\u5C04\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((p, opts) => importCommand(p, opts));
|
|
15151
15471
|
program.command("models [keyword]").description("\u5217\u51FA\u76EE\u6807\u73AF\u5883\u6709\u54EA\u4E9B Model\uFF08describe \u7684\u4E0A\u4E00\u6B65\uFF09\uFF1B\u53EF\u5E26\u5173\u952E\u5B57\u8FC7\u6EE4").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((keyword, opts) => modelsCommand(keyword, opts));
|
|
15152
|
-
program.command("describe <Model>").description("\u67E5\u770B Model \u5143\u6570\u636E\uFF08\u5B57\u6BB5\u3001\u5173\u7CFB\u3001Action \u5217\u8868\uFF09").option("-v, --verbose", "\u663E\u793A\u5B57\u6BB5\u63CF\u8FF0
|
|
15472
|
+
program.command("describe <Model>").description("\u67E5\u770B Model \u5143\u6570\u636E\uFF08\u5B57\u6BB5\u3001\u5173\u7CFB\u3001Action \u5217\u8868\uFF09").option("-v, --verbose", "\u663E\u793A enum \u53D6\u503C\u57DF\uFF0C\u4EE5\u53CA\u81EA\u5B9A\u4E49\u5B57\u6BB5\u7684\u63CF\u8FF0").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((m, opts) => describeCommand(m, opts));
|
|
15473
|
+
var interactions = program.command("interactions").description("\u770B\u89C1\u5E76\u5904\u7406\u4F1A\u8BDD\u91CC\u672A\u51B3\u7684\u6682\u505C\uFF08\u786E\u8BA4 / \u8FFD\u95EE\uFF09\u2014\u2014\u4E0D\u53D1\u65B0\u6D88\u606F\uFF0C\u76F4\u63A5\u56DE\u5230\u90A3\u4E00\u6761");
|
|
15474
|
+
var withInteractionCommonOpts = (cmd) => {
|
|
15475
|
+
cmd.option("--conversation <id>", "\u76EE\u6807\u4F1A\u8BDD\uFF1B\u4E0D\u4F20\u5219\u7528\u672C env \u4E0A\u4E00\u6B21\u804A\u7684\u90A3\u4E2A").option("--agent <uuid>", "\u6307\u5B9A agent UUID\uFF08\u9ED8\u8BA4\u5185\u7F6E analyst\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atext | json", "text");
|
|
15476
|
+
return cmd;
|
|
15477
|
+
};
|
|
15478
|
+
withInteractionCommonOpts(
|
|
15479
|
+
interactions.command("list").description("\u5217\u51FA\u8BE5\u4F1A\u8BDD\u4E0A\u4ECD\u672A\u51B3\u7684\u6682\u505C")
|
|
15480
|
+
).action((opts) => interactionsListCommand(opts));
|
|
15481
|
+
withInteractionCommonOpts(
|
|
15482
|
+
interactions.command("approve <interactionId>").description("\u6279\u51C6\u4E00\u6761\u5199\u786E\u8BA4\u2014\u2014\u5DE5\u5177\u4F1A\u771F\u7684\u518D\u6267\u884C\u4E00\u6B21").option("--timeout <sec>", "\u7B49\u7EC8\u6001\u7684\u79D2\u6570\uFF08\u7EED\u8DD1\u662F\u4E00\u6B21\u5B8C\u6574 LLM \u8F6E\u6B21\uFF09", "180")
|
|
15483
|
+
).action((id, opts) => interactionsRespondCommand("approve", id, opts));
|
|
15484
|
+
withInteractionCommonOpts(
|
|
15485
|
+
interactions.command("reject <interactionId>").description("\u62D2\u7EDD\u4E00\u6761\u5199\u786E\u8BA4").option("--reason <text>", "\u62D2\u7EDD\u7406\u7531\uFF08\u4F1A\u6CE8\u5165\u7EED\u8DD1\u4E0A\u4E0B\u6587\uFF09").option("--timeout <sec>", "\u7B49\u7EC8\u6001\u7684\u79D2\u6570", "180")
|
|
15486
|
+
).action((id, opts) => interactionsRespondCommand("reject", id, opts));
|
|
15487
|
+
withInteractionCommonOpts(
|
|
15488
|
+
interactions.command("answer <interactionId>").description("\u56DE\u7B54\u4E00\u6761\u8FFD\u95EE\uFF08ASK\uFF09").option("--answer <text>", "\u7B54\u6848\u6587\u672C\uFF08\u5FC5\u586B\uFF09").option("--choice <index>", "\u9009\u9879\u4E0B\u6807\uFF0C\u4ECE 0 \u8D77\uFF1B\u53EA\u4F5C\u8865\u5145\uFF0C\u4E0D\u80FD\u66FF\u4EE3 --answer").option("--timeout <sec>", "\u7B49\u7EC8\u6001\u7684\u79D2\u6570", "180")
|
|
15489
|
+
).action((id, opts) => interactionsRespondCommand("answer", id, opts));
|
|
15153
15490
|
program.command("chat [prompt]").description("\u4E0E\u6570\u5B57\u5458\u5DE5 Moirai \u5BF9\u8BDD\uFF1B\u6709 prompt \u5355\u53D1\u540E\u9000\u51FA\uFF0C\u4E0D\u5E26 prompt \u8FDB\u5165 REPL").option("--agent <key>", "\u6307\u5B9A agent UUID\uFF08\u9ED8\u8BA4\u4F7F\u7528 analyst \u5185\u7F6E agent\uFF09").option("--resume <id>", "\u7EED\u63A5\u6307\u5B9A conversation\uFF1B\u4E0D\u4F20\u5219\u9ED8\u8BA4\u5F00\u65B0\u4F1A\u8BDD").option("--conversation <id>", "[deprecated] \u7528 --resume \u66FF\u4EE3\uFF1B\u4F20 NEW \u7B49\u4EF7\u9ED8\u8BA4\u65B0\u4F1A\u8BDD").option("--list", "\u5217\u51FA\u6700\u8FD1\u4F1A\u8BDD\uFF0C\u4E0D\u8FDB\u5165\u804A\u5929").option(
|
|
15154
15491
|
"--events [conversationId]",
|
|
15155
15492
|
"\u53EA\u8BFB\u67E5\u770B\u6307\u5B9A conversation \u7684 timeline/event \u6D41\uFF1B\u4E5F\u53EF\u914D --resume <id>"
|
|
@@ -15220,6 +15557,7 @@ datapackage.command("pack <packageDir>").description("\u628A\u5305\u76EE\u5F55\u
|
|
|
15220
15557
|
datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u5236\u54C1\u5E76\u7ECF\u670D\u52A1\u7AEF\u5F02\u6B65\u5B89\u88C5\u5668\u5B89\u88C5\uFF0C\u5B9E\u65F6\u663E\u793A\u8FDB\u5EA6\uFF08admin.system\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--category <name>", "\u5236\u54C1\u4E0A\u4F20\u7684\u5B58\u50A8\u5206\u7C7B\uFF08\u670D\u52A1\u7AEF\u6570\u636E\u975E\u679A\u4E3E\uFF09", "attachment").option("--no-wait", "\u53EA\u53D7\u7406\u4E0D\u7B49\u5F85\uFF0C\u7ACB\u523B\u8FD4\u56DE runId").option("--timeout <sec>", "\u7B49\u5F85\u4E0A\u9650\uFF08\u79D2\uFF09\uFF1B\u7B49\u4E0D\u5230\u4E0D\u662F\u5931\u8D25\uFF0C\u88C5\u8F7D\u5728\u670D\u52A1\u7AEF\u7EE7\u7EED", "900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((artifact, opts) => datapackageInstallCommand(artifact, opts));
|
|
15221
15558
|
datapackage.command("status <runId>").description("\u67E5\u770B\u88C5\u8F7D\u6D41\u6C34\u8FDB\u5EA6/\u7EC8\u6001\uFF08\u914D\u5408 install --no-wait \u6216\u7B49\u5F85\u8D85\u65F6\u540E\u4F7F\u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((runId, opts) => datapackageStatusCommand(runId, opts));
|
|
15222
15559
|
var tenant = program.command("tenant").description("\u79DF\u6237\u5F00\u901A\u4E0E\u751F\u547D\u5468\u671F");
|
|
15560
|
+
tenant.command("reset").description("\u4EE5\u5F53\u524D\u79DF\u6237\u5185\u7F6E admin \u91CD\u7F6E PostgreSQL \u5230\u51FA\u5382\u57FA\u7EBF\uFF1B\u4E0D\u53EF\u9006\uFF0C\u975E PG \u672A\u5904\u7406\u672A\u6838\u9A8C").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4F7F\u7528\u8BE5\u73AF\u5883\u7684\u76F4\u63A5\u767B\u5F55\u8EAB\u4EFD\uFF0C\u4E0D\u63A5\u53D7\u4EE3\u7406").option("-y, --yes", "\u786E\u8BA4\u91CD\u7F6E\u5DF2\u6838\u9A8C\u7684\u5F53\u524D\u79DF\u6237\uFF0C\u8DF3\u8FC7\u4EA4\u4E92").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => tenantResetCommand(opts));
|
|
15223
15561
|
tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5EFA\u79DF\u6237 + admin \u7528\u6237 + \u7ED3\u6784 reconcile\uFF09\u2014\u2014\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8").requiredOption("--tenant-id <id>", "\u79DF\u6237 ID").requiredOption("--admin-username <user>", "\u7BA1\u7406\u5458\u7528\u6237\u540D").option(
|
|
15224
15562
|
"--admin-password <pwd>",
|
|
15225
15563
|
"\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --admin-password-stdin\uFF09"
|