feat(workflow): 支持节点 displayName 并限制 20 字标题

- 新增 --display-name,写入设计器真正持久化的节点标题 displayName;--label 保留为节点类型标题
- 新增/编辑/映射节点统一校验节点标题不超过 20 个 Unicode 字符,超出时本地直接拒绝
- 节点列表与详情优先展示 displayName,并在使用 --label 时提示服务端可能重新生成
- 记录后端不限制长度、仅前端设计器限制 20 字的验证结论
- 补充节点变更单测与 CLI 共享 flag 词表
This commit is contained in:
gitea committed 2026-10-28 10:55:56 +08:00
1 parent 96f4148f67
commit 1a2e485caa
6 files changed
+453 -366

No files matched your search

+22 -9
View File
@@ -158,13 +158,13 @@ async function handleListNodes(
item.hierarchicalIndex,
item.task.name,
item.task.type,
item.task.label || "-",
item.task.displayName || item.task.label || "-",
item.task.groupName || "-",
item.summary,
]);
const table = printTable(
["#", "节点标识 (name)", "类型 (type)", "标题 (label)", "分组", "配置摘要"],
["#", "节点标识 (name)", "类型 (type)", "标题", "分组", "配置摘要"],
rows
);
@@ -219,6 +219,7 @@ async function handleGetNode(
"父容器节点": parentName || "顶级节点 (root)",
"节点类型 (type)": task.type,
"节点标题 (label)": task.label || "-",
"节点显示名 (displayName)": (task as any).displayName || "-",
"节点分组 (group)": task.groupName || "-",
"状态 (status)": task.status || "active",
};
@@ -228,7 +229,7 @@ async function handleGetNode(
}
const outLines = [
`====== 节点详情 [${task.name}] (${task.label || task.type}) ======`,
`====== 节点详情 [${task.name}] (${(task as any).displayName || task.label || task.type}) ======`,
printKeyValue(kv),
];
@@ -255,7 +256,8 @@ async function handleAddNode(
"",
"常用选项:",
" --type=<type> 节点类型 (如 code-js2 / code)",
" --label=<标题> 节点显示名称",
" --label=<标题> 节点类型标题",
" --display-name=<名称> 设计器节点标题(displayName,最多 20 字符)",
" --code-file=<脚本路径> (推荐) 从本地文件导入代码,避免终端转义与 Token 浪费",
" --code=<代码片段> 传入代码字符串(仅限简短代码)",
" --parent=<容器节点name> 插入指定容器节点内部 (如 every 循环)",
@@ -269,6 +271,7 @@ async function handleAddNode(
}
const label = stringOption(parsed.options, ["label", "name", "l"]);
const displayName = stringOption(parsed.options, ["display-name", "displayName", "display"]);
const parent = stringOption(parsed.options, ["parent", "container", "p"]);
const after = stringOption(parsed.options, ["after", "insert-after"]);
const desc = stringOption(parsed.options, ["desc", "description", "d"]);
@@ -284,7 +287,7 @@ async function handleAddNode(
parsed,
runtime,
"追加工作流节点",
`hose-use workflow node add ${pipelineId} --type=${type}${label ? ` --label="${label}"` : ""}${parent ? ` --parent="${parent}"` : ""}${after ? ` --after="${after}"` : ""} --yes`
`hose-use workflow node add ${pipelineId} --type=${type}${label ? ` --label="${label}"` : ""}${displayName ? ` --display-name="${displayName}"` : ""}${parent ? ` --parent="${parent}"` : ""}${after ? ` --after="${after}"` : ""} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
@@ -293,6 +296,7 @@ async function handleAddNode(
const { workflow: updatedWorkflow, newTask } = addWorkflowTask(detail, {
type,
label,
displayName,
desc,
code,
parent,
@@ -305,6 +309,7 @@ async function handleAddNode(
newNodeName: newTask.name,
type: newTask.type,
label: newTask.label,
displayName: newTask.displayName,
targetLocation: parent ? `容器 [${parent}] 内部` : after ? `节点 [${after}] 之后` : "工作流末尾",
totalTasksCount: updatedWorkflow.tasks?.length || 0,
});
@@ -321,11 +326,12 @@ async function handleAddNode(
}
const out = [
`✨ 节点 [${newTask.name}] (${newTask.label}) 已成功添加至工作流 [${pipelineId}]:`,
`✨ 节点 [${newTask.name}] (${newTask.displayName || newTask.label}) 已成功添加至工作流 [${pipelineId}]:`,
printKeyValue({
"节点标识 (name)": newTask.name,
"节点类型 (type)": newTask.type,
"节点标题 (label)": newTask.label || "-",
"节点显示名 (displayName)": newTask.displayName || "-",
"所属位置": parent ? `容器 [${parent}] 内部` : after ? `节点 [${after}] 之后` : "工作流顶级末尾",
"节点总数": String(saveResult.tasks?.length || updatedWorkflow.tasks?.length || 0),
}),
@@ -347,7 +353,8 @@ async function handleEditNode(
"请提供节点标识 (name 或层级序号): hose-use workflow node edit <pipelineId> <nodeNameOrIndex> [选项]",
"",
"常用选项:",
" --label=<新名称> 更新节点显示标题",
" --label=<类型标题> 更新节点类型标题(服务端保存时可能重新生成)",
" --display-name=<新名称> 更新设计器节点标题(displayName,最多 20 字符)",
" --code-file=<脚本路径> (推荐) 从本地文件导入最新脚本,避免终端转义与 Token 浪费",
" --code=<行内代码> 直接传入代码片段(短脚本)",
" --desc=<描述> 更新节点描述",
@@ -363,6 +370,7 @@ async function handleEditNode(
}
const label = stringOption(parsed.options, ["label", "l"]);
const displayName = stringOption(parsed.options, ["display-name", "displayName", "display"]);
const desc = stringOption(parsed.options, ["desc", "description", "d"]);
const codeFile = stringOption(parsed.options, ["code-file", "file"]);
let code = stringOption(parsed.options, ["code", "c"]);
@@ -399,7 +407,7 @@ async function handleEditNode(
parsed,
runtime,
"修改工作流节点",
`hose-use workflow node edit ${pipelineId} ${nodeTarget}${label ? ` --label="${label}"` : ""} --yes`
`hose-use workflow node edit ${pipelineId} ${nodeTarget}${label ? ` --label="${label}"` : ""}${displayName ? ` --display-name="${displayName}"` : ""} --yes`
);
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
@@ -407,6 +415,7 @@ async function handleEditNode(
const { workflow: updatedWorkflow, editedTask } = editWorkflowTask(detail, nodeTarget, {
label,
displayName,
desc,
code,
set: Object.keys(customSet).length > 0 ? customSet : undefined,
@@ -419,6 +428,7 @@ async function handleEditNode(
label: editedTask.label,
updatedFields: {
...(label ? { label } : {}),
...(displayName !== undefined ? { displayName } : {}),
...(desc ? { desc } : {}),
...(code !== undefined ? { code: `${code.length} 字符${!codeFile && code.length > 300 ? " [TIP: 建议使用 --code-file=<path> 从本地文件载入以规避转义错误并节省 Token]" : ""}` } : {}),
...customSet,
@@ -440,9 +450,12 @@ async function handleEditNode(
if (!codeFile && code && code.length > 300) {
codeTip = `\n💡 提示: 检测到通过命令行行内传入大段代码 (${code.length} 字符)。建议将脚本落地为本地文件并通过 --code-file=<路径> 传入,避免 Token 浪费与 Shell 转义风险。\n`;
}
const labelTip = label
? "\n💡 提示: --label 是节点类型标题,服务端保存时可能重新生成;要修改设计器标题请使用 --display-name。\n"
: "";
return {
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n${codeTip}`,
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n${codeTip}${labelTip}`,
stderr: "",
exitCode: 0,
};