feat(workflow,corps): add dynamic staff link switching and deep failed job inspection

This commit is contained in:
gitea committed 2026-10-14 18:32:14 +08:00
1 parent 0499ccb2cc
commit 0c6a3ee660
8 files changed
+737 -32

No files matched your search

+129 -24
View File
@@ -1,9 +1,13 @@
import {
extractFailureExecutions,
findExecutionNode,
flattenExecutionTree,
getExecutionLogs,
getJob,
getJobExecutionLevel,
getJobExecutionTree,
getJobFailedExecutions,
isTaskExecutionFailed,
listPlatforms,
} from "../../../domains/platform/services.js";
import type { WorkflowTaskExecution } from "../../../domains/platform/types.js";
@@ -101,7 +105,7 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
if (!jobId) {
return {
stdout: "",
stderr: "用法: hose-use workflow job <jobId> [--failed] [--parent=<executionId>] [--logs=<executionId>]\n",
stderr: "用法: hose-use workflow job <jobId> [--failed] [--node=<name|id>] [--verbose] [--parent=<executionId>] [--logs=<executionId>]\n",
exitCode: 1,
};
}
@@ -111,7 +115,9 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
const pageSize = numberOption(parsed.options, ["page-size", "pageSize", "size"]) || 100;
const logsExecutionId = stringOption(parsed.options, ["logs", "log", "execution-logs"]);
const parentExecutionId = stringOption(parsed.options, ["parent", "parent-id", "parentId"]);
const nodeQuery = stringOption(parsed.options, ["node", "task", "node-id", "nodeId"]);
const onlyFailed = booleanOption(parsed.options, ["failed", "fail", "errors"]);
const verbose = booleanOption(parsed.options, ["verbose", "v"]);
// 1. --logs=<executionId>
if (logsExecutionId) {
@@ -208,21 +214,100 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
};
}
// 3. --failed
// 3. --node=<name|id>
if (nodeQuery) {
const tree = await getJobExecutionTree(client, jobId);
const matchedNode = findExecutionNode(tree, nodeQuery);
if (!matchedNode) {
return {
stdout: "",
stderr: `未在 Job [${jobId}] 的执行树中找到匹配 "${nodeQuery}" 的节点。请核对节点名称或 Execution ID。\n`,
exitCode: 1,
};
}
if (runtime.jsonMode) {
return {
stdout: printJson({ jobId, node: matchedNode }, runtime.outputOptions),
stderr: "",
exitCode: 0,
};
}
const anyNode = matchedNode as any;
const inputPayload = anyNode.inputs ?? anyNode.form ?? anyNode.params;
const outputPayload = anyNode.outputs ?? anyNode.output ?? anyNode.details;
const lines = [
`====== 工作流节点执行详情 [${matchedNode.id}] (Job: ${jobId}) ======`,
printKeyValue({
"Execution ID": matchedNode.id,
"Parent ID": matchedNode.parentId || "-",
"节点标识 (name)": matchedNode.name || "-",
"节点名称": matchedNode.displayName || matchedNode.label || "-",
"节点类型 (type)": matchedNode.type || "-",
"执行状态 (status)": matchedNode.status || anyNode.state || "-",
"耗时(ms)": String(matchedNode.executionTime ?? anyNode.durationTime ?? "-"),
"开始时间": String(matchedNode.startTime || anyNode.createTime || "-"),
"结束时间": String(matchedNode.endTime || "-"),
"循环路径": matchedNode.currentLoopPath || "-",
...(matchedNode.error?.message ? { "错误信息": matchedNode.error.message } : {}),
}),
];
if (matchedNode.error?.message) {
lines.push("");
lines.push("── ❌ 错误堆栈 / 原因 ──");
lines.push(matchedNode.error.message);
if (anyNode.error?.stack) {
lines.push(anyNode.error.stack);
}
}
if (inputPayload !== undefined) {
lines.push("");
lines.push("── 📥 节点入参报文 (inputs / form) ──");
lines.push(typeof inputPayload === "string" ? inputPayload : JSON.stringify(inputPayload, null, 2));
}
if (outputPayload !== undefined) {
lines.push("");
lines.push("── 📤 节点出参 / 响应结果 (outputs) ──");
lines.push(typeof outputPayload === "string" ? outputPayload : JSON.stringify(outputPayload, null, 2));
}
lines.push("");
return {
stdout: `${lines.join("\n")}\n`,
stderr: "",
exitCode: 0,
};
}
// 4. --failed
if (onlyFailed) {
const [job, failedPage] = await Promise.all([
const [job, tree, failedPage] = await Promise.all([
getJob(client, jobId).catch(() => undefined),
getJobFailedExecutions(client, jobId),
getJobExecutionTree(client, jobId).catch(() => []),
getJobFailedExecutions(client, jobId).catch(() => ({
number: 1,
size: 100,
totalPages: 0,
totalItems: 0,
items: [] as WorkflowTaskExecution[],
})),
]);
const enrichedItems = await enrichFailedExecutions(client, jobId, failedPage.items);
const rawFailed = extractFailureExecutions(tree, failedPage.items);
const enrichedItems = await enrichFailedExecutions(client, jobId, rawFailed);
if (runtime.jsonMode) {
return {
stdout: printJson(
{
jobId,
job: job ?? null,
totalItems: failedPage.totalItems,
items: enrichedItems,
totalFailed: enrichedItems.length,
failedNodes: enrichedItems,
},
runtime.outputOptions
),
@@ -231,34 +316,53 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
};
}
const rows = enrichedItems.map((item, idx) => [
const rows = enrichedItems.map((item: any, idx) => [
idx + 1,
item.id,
item.parentId || "-",
item.name || "-",
item.type || "-",
item.status || "-",
item.currentLoopPath || "-",
item.error?.message || "-",
item.displayName || item.label || item.type || "-",
item.status || item.state || "-",
String(item.executionTime ?? item.durationTime ?? "-"),
item.error?.message || item.errorMessage || item.outputs?.error || "-",
]);
const formSummaries: string[] = [];
const nodeDetailBlocks: string[] = [];
const shouldExpand = verbose || enrichedItems.length <= 5;
for (const item of enrichedItems) {
if (item.error?.message || item.form !== undefined) {
formSummaries.push(
`\n── ⚠️ 异常节点 [${item.id}] (${item.name || "-"} | status=${item.status} | loop=${item.currentLoopPath || "-"}) ──`
const anyItem = item as any;
const errMsg = item.error?.message || anyItem.errorMessage || anyItem.outputs?.error;
const inputPayload = anyItem.inputs ?? anyItem.form ?? anyItem.params;
const outputPayload = anyItem.outputs ?? anyItem.output ?? anyItem.details;
if (errMsg || inputPayload !== undefined || outputPayload !== undefined) {
nodeDetailBlocks.push(
`\n── ⚠️ 异常节点 [${item.id}] (${item.name || "-"} | ${item.displayName || item.label || item.type || "-"} | status=${item.status || anyItem.state}) ──`
);
if (item.error?.message) {
formSummaries.push(` 错误详情: ${item.error.message}`);
if (errMsg) {
nodeDetailBlocks.push(` ❌ 错误原因: ${errMsg}`);
}
if (item.form !== undefined) {
formSummaries.push(` 表单入参 (form): ${JSON.stringify(item.form)}`);
if (shouldExpand) {
if (inputPayload !== undefined) {
const inStr = typeof inputPayload === "string" ? inputPayload : JSON.stringify(inputPayload, null, 2);
nodeDetailBlocks.push(` 📥 节点入参 (inputs/form):\n${inStr.split("\n").map((l: string) => " " + l).join("\n")}`);
}
if (outputPayload !== undefined) {
const outStr = typeof outputPayload === "string" ? outputPayload : JSON.stringify(outputPayload, null, 2);
nodeDetailBlocks.push(` 📤 节点出参 (outputs/details):\n${outStr.split("\n").map((l: string) => " " + l).join("\n")}`);
}
} else {
if (inputPayload !== undefined) {
nodeDetailBlocks.push(` 📥 节点入参: [已省略,使用 --verbose 查看完整 JSON]`);
}
}
}
}
return {
stdout: [
`====== Job 异常/跳过执行节点明细 (Job: ${jobId}) ======`,
`====== Job 异常/失败执行节点透视 (Job: ${jobId}) ======`,
job
? printKeyValue({
"Job ID": job.id,
@@ -266,16 +370,17 @@ export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Pro
"Job 状态": job.state ?? job.status,
"开始时间": job.startTime || "-",
"耗时(ms)": String(job.durationTime ?? "-"),
"失败节点数": enrichedItems.length,
})
: "",
"",
rows.length
? printTable(
["#", "Execution ID", "Parent ID", "节点标识 (name)", "类型 (type)", "状态 (status)", "循环路径 (currentLoopPath)", "错误原因 (error.message)"],
["#", "Execution ID", "Parent ID", "节点标识 (name)", "节点名称/类型", "状态", "耗时(ms)", "错误原因"],
rows
)
: "未发现异常或报错跳过的执行节点",
...formSummaries,
: "✅ 未发现任何异常或报错失败的执行节点",
...nodeDetailBlocks,
"",
].filter(Boolean).join("\n"),
stderr: "",