feat: 完善工作流工具链与大结果保护
- 工作流节点描述增加服务端托管黑名单,仅代码节点保留自定义 desc - 工作流保存新增 --in-place,并改进版本冲突提示 - platform records 新增 --page 分页,--all 强制走 ndjson 文件流 - platform schema 展示 ownerId/submitterId 等系统字段 - 更新 Agent Skill 的代码节点 agent use 标记规范 - 补充对应测试与文档
This commit is contained in:
1 parent
37643da254
commit
7423e166a1
10 files changed
+123
-20
No files matched your search
@@ -14,7 +14,7 @@ import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js
|
||||
import { printJson } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS } from "./shared.js";
|
||||
import { PLATFORM_ID_OPTION_KEYS, formatWorkflowVersion } from "./shared.js";
|
||||
|
||||
export async function handlePatch(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
@@ -78,7 +78,7 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
if (!pipelineId || !file) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose-use workflow save <pipelineId> --file=<workflow.json> [--force-write]\n",
|
||||
stderr: "用法: hose-use workflow save <pipelineId> --file=<workflow.json> [--force-write] [--in-place]\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -96,6 +96,7 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
}
|
||||
|
||||
const forceWrite = booleanOption(parsed.options, ["force-write", "forceWrite"]);
|
||||
const syncFile = booleanOption(parsed.options, ["in-place", "inPlace"]);
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
@@ -105,8 +106,10 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "保存工作流草稿到远端", pipelineId, {
|
||||
file,
|
||||
version: parsedWorkflow.version,
|
||||
tasksVersion: parsedWorkflow.tasksVersion,
|
||||
forceWrite,
|
||||
syncFile,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,28 +127,48 @@ export async function handleSave(parsed: CliParsedArgs, runtime: CliRuntime): Pr
|
||||
|
||||
if (!forceWrite && hasWorkflowVersionConflict(state, remote)) {
|
||||
throw new Error(
|
||||
`工作流版本已变化,拒绝覆盖:远端 tasksVersion=${remote.tasksVersion}, 文件 tasksVersion=${parsedWorkflow.tasksVersion}。确认来源后使用 --force-write。`
|
||||
`工作流版本已变化,拒绝覆盖:远端 tasksVersion=${remote.tasksVersion}, 文件 tasksVersion=${parsedWorkflow.tasksVersion}。请重新导出最新工作流后再改;后续保存可加 --in-place 自动同步本地文件版本。确认要覆盖时使用 --force-write。`
|
||||
);
|
||||
}
|
||||
|
||||
state = beginWorkflowSave(state);
|
||||
const localWorkflowForSync = state.workflow;
|
||||
try {
|
||||
const payload = state.workflow.inputs?.length
|
||||
? state.workflow
|
||||
: { ...state.workflow, inputs: [{ key: "$platformId", value: platformId }] };
|
||||
const saved = await updateWorkflow(piperClient, payload);
|
||||
state = commitWorkflowSave(state, saved);
|
||||
let fileSynced = false;
|
||||
let fileSyncWarning = "";
|
||||
if (syncFile) {
|
||||
try {
|
||||
const syncedWorkflow = {
|
||||
...localWorkflowForSync,
|
||||
version: saved.version,
|
||||
tasksVersion: saved.tasksVersion,
|
||||
updateTime: saved.updateTime,
|
||||
};
|
||||
writeFileSync(file, `${JSON.stringify(syncedWorkflow, null, 2)}\n`, "utf8");
|
||||
fileSynced = true;
|
||||
} catch (error) {
|
||||
fileSyncWarning = `本地文件同步失败: ${error instanceof Error ? error.message : String(error)}`;
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
success: true,
|
||||
pipelineId,
|
||||
status: state.status,
|
||||
version: saved.version,
|
||||
tasksVersion: saved.tasksVersion,
|
||||
updateTime: saved.updateTime,
|
||||
fileSynced,
|
||||
...(fileSyncWarning ? { fileSyncWarning } : {}),
|
||||
};
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: fileSyncWarning, exitCode: 0 };
|
||||
return {
|
||||
stdout: `✅ 工作流 [${pipelineId}] 草稿保存成功,tasksVersion=${saved.tasksVersion}。\n`,
|
||||
stderr: "",
|
||||
stdout: `✅ 工作流 [${pipelineId}] 草稿保存成功:${formatWorkflowVersion(saved)}。${fileSynced ? "\n📝 已同步更新本地文件。" : ""}${fileSyncWarning ? `\n⚠️ ${fileSyncWarning}` : ""}\n`,
|
||||
stderr: fileSyncWarning,
|
||||
exitCode: 0,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@@ -14,12 +14,13 @@ import {
|
||||
GRAY_NODES_CATALOG,
|
||||
findGrayNode,
|
||||
} from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { isServerManagedDescType } from "../../../domains/platform/workflow/nodes/mutations.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createPiperClientForCorp } from "../../helpers.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
import { createWorkflowDetailClient, formatWorkflowVersion } from "./shared.js";
|
||||
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "map", "rm", "remove", "delete", "del"]);
|
||||
const CORP_LEVEL_ACTIONS = new Set(["available", "list-available", "catalog", "probe", "grant", "open"]);
|
||||
@@ -334,6 +335,7 @@ async function handleAddNode(
|
||||
"节点显示名 (displayName)": newTask.displayName || "-",
|
||||
"所属位置": parent ? `容器 [${parent}] 内部` : after ? `节点 [${after}] 之后` : "工作流顶级末尾",
|
||||
"节点总数": String(saveResult.tasks?.length || updatedWorkflow.tasks?.length || 0),
|
||||
"工作流版本": formatWorkflowVersion(saveResult),
|
||||
}),
|
||||
].join("\n");
|
||||
|
||||
@@ -420,6 +422,7 @@ async function handleEditNode(
|
||||
code,
|
||||
set: Object.keys(customSet).length > 0 ? customSet : undefined,
|
||||
});
|
||||
const descManaged = desc !== undefined && isServerManagedDescType(editedTask.type);
|
||||
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "修改工作流节点", `${pipelineId}:${editedTask.name}`, {
|
||||
@@ -429,7 +432,8 @@ async function handleEditNode(
|
||||
updatedFields: {
|
||||
...(label ? { label } : {}),
|
||||
...(displayName !== undefined ? { displayName } : {}),
|
||||
...(desc ? { desc } : {}),
|
||||
...(desc && !descManaged ? { desc } : {}),
|
||||
...(descManaged ? { desc: "服务端托管,已跳过" } : {}),
|
||||
...(code !== undefined ? { code: `${code.length} 字符${!codeFile && code.length > 300 ? " [TIP: 建议使用 --code-file=<path> 从本地文件载入以规避转义错误并节省 Token]" : ""}` } : {}),
|
||||
...customSet,
|
||||
},
|
||||
@@ -440,7 +444,7 @@ async function handleEditNode(
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult }, runtime.outputOptions),
|
||||
stdout: printJson({ success: true, pipelineId, editedTask, workflow: saveResult, descIgnored: descManaged }, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -453,9 +457,12 @@ async function handleEditNode(
|
||||
const labelTip = label
|
||||
? "\n💡 提示: --label 是节点类型标题,服务端保存时可能重新生成;要修改设计器标题请使用 --display-name。\n"
|
||||
: "";
|
||||
const descTip = descManaged
|
||||
? "\n💡 提示: 该节点描述由服务端按配置自动生成,--desc 已忽略;如需稳定说明,请使用代码节点或在创建节点上写业务说明。\n"
|
||||
: "";
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n${codeTip}${labelTip}`,
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.displayName || editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n${codeTip}${labelTip}${descTip}`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -545,7 +552,7 @@ async function handleMapNode(
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 已批量应用映射: ${changedKeys.join(", ")},并已保存至工作流 [${pipelineId}]。\n`,
|
||||
stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 已批量应用映射: ${changedKeys.join(", ")},并已保存至工作流 [${pipelineId}]。\n📌 ${formatWorkflowVersion(saveResult)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -598,7 +605,7 @@ async function handleRemoveNode(
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `🗑️ 节点 [${removedTask.name}] (${removedTask.label || removedTask.type}) 已从工作流 [${pipelineId}] 中安全移除。\n`,
|
||||
stdout: `🗑️ 节点 [${removedTask.name}] (${removedTask.label || removedTask.type}) 已从工作流 [${pipelineId}] 中安全移除。\n📌 ${formatWorkflowVersion(saveResult)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
|
||||
@@ -5,6 +5,17 @@ import type { CliParsedArgs, CliRuntime } from "../../types.js";
|
||||
|
||||
export const PLATFORM_ID_OPTION_KEYS = ["platform", "platform-id", "platformId", "app", "app-id", "appId"];
|
||||
|
||||
export function formatWorkflowVersion(workflow: {
|
||||
version?: string | null;
|
||||
tasksVersion?: number | null;
|
||||
updateTime?: string | null;
|
||||
}): string {
|
||||
const version = workflow.version || "-";
|
||||
const tasksVersion = workflow.tasksVersion ?? "-";
|
||||
const updateTime = workflow.updateTime ? `,更新时间 ${workflow.updateTime}` : "";
|
||||
return `版本 ${version}(tasksVersion ${tasksVersion})${updateTime}`;
|
||||
}
|
||||
|
||||
export async function createWorkflowDetailClient(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime,
|
||||
|
||||
Reference in new issue
Block a user