From 1739daacf2e4d98e647011b924f144a6900e086f Mon Sep 17 00:00:00 2001 From: yunyingk Date: Fri, 23 Oct 2026 11:46:14 +0800 Subject: [PATCH] chore(workflow): enforce --code-file and file-based editing to eliminate token waste --- skills/hose-use/SKILL.md | 10 ++++-- skills/hose-use/multi/ekuaibao-mvel/SKILL.md | 8 +++++ skills/hose-use/references/workflow.md | 12 ++++--- src/cli/commands/workflow/node.ts | 37 +++++++++++++++++--- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md index bca9a8f..7d76a91 100644 --- a/skills/hose-use/SKILL.md +++ b/skills/hose-use/SKILL.md @@ -66,6 +66,12 @@ metadata: - **高阶管理人员权限风控识别**:合思协助平台具备直接借用企业任意员工身份(包含主管理员、企业法定代表人、财务负责人/总监、VP/总裁等高管身份)的高危能力。当获取的身份命中高管关键词(总监、主管、主管理员、总经理等)或具备 `SYS_ADMIN` / `CORP_PAYMENT_MANAGE` 权限时,系统会自动发出醒目的高管权限风控警示框; - **防范越权与误用硬约束**:一线实施、运维人员或 AI Agent 严禁借用高管特权身份在系统内代行审批通过、款项拨付或提交非授权配置!所有协助权限必须严格局限在系统排障、配置诊断、数据核验与接口联调,严禁进行越权业务审批; - **协助时长服务端硬性上限**:协助平台工单申请(`POST /api/assistPlatform/create`)受服务端硬性安全管控,单次最长有效时间为 24 小时(1天),超过 24 小时服务端直接返回 400 拒绝。如需持续维护,可在工单到期后再次发起或在端内续签。 +14. **工作流代码节点文件映射与 Token 防膨胀守则 (Workflow Code Node File Mapping & Zero-Token-Waste Rule)**: + - **严禁终端内联大段代码**:在新建或修改工作流代码节点(`code-js2` / `code`)时,**严禁使用 `--code="..."` 或在终端命令(如 `bun -e '...'`)中内联几十上百行的长代码**。内联大段代码会导致命令行参数急剧膨胀,在 Tool Calls 中产生严重的输入输出 Token 浪费,且极易因 Shell 引号转义损坏脚本语法; + - **必须走本地文件映射与 `--code-file`**: + 1. **导出/映射**:先将节点代码提取至本地独立文件(如 `scripts/clean.js` 或 `scripts/amortize.mvel`),或使用 `hose-use workflow node get > ./scripts/xxx.mvel`; + 2. **微创修改(Diff Edit)**:在本地文件上使用编辑工具进行精准、局部的差异修改(仅消耗几行 diff 的极少 Token); + 3. **一键同步**:使用 `hose-use workflow node edit --code-file=./scripts/xxx.mvel --yes`(或 `node add ... --code-file=...`)通过文件流同步至云端。 --- @@ -227,8 +233,8 @@ hose-use workflow webhook send wf_01k83y... --bill=<单号> --yes # 向 Webhoo hose-use workflow delete wf_01k83y... --yes # 安全删除工作流 (支持 rm, remove, 带 --dry-run 预览) hose-use workflow node list wf_01k83y... # 树形层级索引查看工作流任务节点树与摘要 (别名 ls) hose-use workflow node get wf_01k83y... <节点name或#序号> # 查看指定节点的完整配置 (别名 show, info) -hose-use workflow node add wf_01k83y... --type=code-js2 --label="清洗" --code="return items;" --yes # 声明式追加节点 (--after/--parent 插入) -hose-use workflow node edit wf_01k83y... <节点name或#序号> --label="新标题" --yes # 定向修改节点配置 +hose-use workflow node add wf_01k83y... --type=code-js2 --label="清洗" --code-file=./clean.js --yes # 声明式追加节点 (支持 --code-file 导入) +hose-use workflow node edit wf_01k83y... <节点name或#序号> --code-file=./clean.js --yes # 从本地文件同步最新脚本 (推荐,零 Token 浪费) hose-use workflow node rm wf_01k83y... <节点name或#序号> --yes # 安全移除任务节点 (首节点触发器安全防御) hose-use workflow tail wf_01k83y... # 类似 tail -f 实时监听新任务派发与节点执行日志流 (别名 watch, follow) hose-use workflow tail wf_01k83y... --job= # 针对单个执行中的 Job 实时跟踪直至终态 diff --git a/skills/hose-use/multi/ekuaibao-mvel/SKILL.md b/skills/hose-use/multi/ekuaibao-mvel/SKILL.md index 871ef0b..fe5340f 100644 --- a/skills/hose-use/multi/ekuaibao-mvel/SKILL.md +++ b/skills/hose-use/multi/ekuaibao-mvel/SKILL.md @@ -144,3 +144,11 @@ result; Then add one field access at a time. For code nodes nested inside a condition branch, still return a normal object from the code node; only condition expressions themselves must return boolean. Treat tenant-specific behavior as evidence, not a universal rule. Say what assumption the code is using when syntax compatibility is uncertain. + +## Deployment & CLI Integration (Zero-Token-Waste Rule) + +- **Always maintain MVEL scripts in local dedicated files** (e.g. `./scripts/node_calc.mvel`), never pass long scripts inline in `--code="..."` or in terminal `bun -e '...'` expressions. +- **Local syntax check**: `hose-use workflow lint-script --file=./scripts/node_calc.mvel --type=code` +- **Deploy to workflow node**: `hose-use workflow node edit --code-file=./scripts/node_calc.mvel --yes` +- **End-to-end cloud simulation test**: `hose-use workflow test --flow --yes --force` + diff --git a/skills/hose-use/references/workflow.md b/skills/hose-use/references/workflow.md index 6bde065..8a33c82 100644 --- a/skills/hose-use/references/workflow.md +++ b/skills/hose-use/references/workflow.md @@ -321,15 +321,17 @@ hose-use workflow node get 2 --json # 3. 声明式向工作流追加或定向插入新节点 (别名: append, insert) # 默认追加至流程末尾;支持通过 --parent=<容器节点> 插入循环/分支内,或 --after=<节点> 插入指定节点后 -hose-use workflow node add --type=code-js2 --label="数据过滤" --code="return items.filter(x => x.amount > 0);" --dry-run -hose-use workflow node add --type=code-js2 --label="数据过滤" --code="return items.filter(x => x.amount > 0);" --yes +# 推荐做法(零 Token 浪费 & 避开命令行转义):从本地脚本文件导入代码 +hose-use workflow node add --type=code-js2 --label="数据过滤" --code-file=./scripts/filter.js --yes hose-use workflow node add --type=stop --label="超额阻断" --after=action_dx9cci --yes hose-use workflow node add --type=http --label="外部通知" --parent=control_every_1 --yes # 4. 定向修改指定节点配置 (别名: update, set) -# 支持修改 --label, --desc, --code, 或通过 --set="key=value" 定向覆盖任意属性 -hose-use workflow node edit action_dx9cci --label="清洗增强版" --code="return items;" --dry-run -hose-use workflow node edit action_dx9cci --label="清洗增强版" --code="return items;" --yes +# 支持修改 --label, --desc, --code, --code-file, 或通过 --set="key=value" 定向覆盖任意属性 +# 推荐做法(零 Token 浪费 & 避开命令行转义):从本地文件导入脚本 +hose-use workflow node edit action_dx9cci --code-file=./scripts/clean.js --dry-run +hose-use workflow node edit action_dx9cci --code-file=./scripts/clean.js --yes +hose-use workflow node edit action_dx9cci --label="清洗增强版" --yes hose-use workflow node edit 2 --set="method=GET" --yes # 5. 安全移除指定任务节点 (别名: remove, delete, del) diff --git a/src/cli/commands/workflow/node.ts b/src/cli/commands/workflow/node.ts index 49cf7f1..902df8f 100644 --- a/src/cli/commands/workflow/node.ts +++ b/src/cli/commands/workflow/node.ts @@ -248,7 +248,17 @@ async function handleAddNode( stderr: [ "请指定新增节点类型: --type=<类型>", "常见类型: code-js2 (JS脚本), code (MVEL代码), http (HTTP请求), stop (终止流程), every (循环遍历), condition (分支条件)", - "示例: hose-use workflow node add 896398895352487950 --type=code-js2 --label='数据清洗' --yes", + "", + "常用选项:", + " --type= 节点类型 (如 code-js2 / code)", + " --label=<标题> 节点显示名称", + " --code-file=<脚本路径> (推荐) 从本地文件导入代码,避免终端转义与 Token 浪费", + " --code=<代码片段> 传入代码字符串(仅限简短代码)", + " --parent=<容器节点name> 插入指定容器节点内部 (如 every 循环)", + " --after=<前置节点name> 插入指定节点之后", + " --yes 确认追加", + "", + "示例: hose-use workflow node add 896398895352487950 --type=code-js2 --label='数据清洗' --code-file=./clean.js --yes", ].join("\n") + "\n", exitCode: 1, }; @@ -329,7 +339,21 @@ async function handleEditNode( if (!nodeTarget) { return { stdout: "", - stderr: "请提供节点标识 (name 或层级序号): hose-use workflow node edit [选项]\n", + stderr: [ + "请提供节点标识 (name 或层级序号): hose-use workflow node edit [选项]", + "", + "常用选项:", + " --label=<新名称> 更新节点显示标题", + " --code-file=<脚本路径> (推荐) 从本地文件导入最新脚本,避免终端转义与 Token 浪费", + " --code=<行内代码> 直接传入代码片段(短脚本)", + " --desc=<描述> 更新节点描述", + " --set='key=value' 定向修改节点自定义属性", + " --dry-run 只预览变更", + " --yes 确认保存修改", + "", + "示例:", + " hose-use workflow node edit 900682164608835609 action_cdd6fv --code-file=./clean.mvel --yes", + ].join("\n") + "\n", exitCode: 1, }; } @@ -384,7 +408,7 @@ async function handleEditNode( updatedFields: { ...(label ? { label } : {}), ...(desc ? { desc } : {}), - ...(code !== undefined ? { code: `${code.length} 字符` } : {}), + ...(code !== undefined ? { code: `${code.length} 字符${!codeFile && code.length > 300 ? " [TIP: 建议使用 --code-file= 从本地文件载入以规避转义错误并节省 Token]" : ""}` } : {}), ...customSet, }, }); @@ -400,8 +424,13 @@ async function handleEditNode( }; } + let codeTip = ""; + if (!codeFile && code && code.length > 300) { + codeTip = `\n💡 提示: 检测到通过命令行行内传入大段代码 (${code.length} 字符)。建议将脚本落地为本地文件并通过 --code-file=<路径> 传入,避免 Token 浪费与 Shell 转义风险。\n`; + } + return { - stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n`, + stdout: `✅ 节点 [${editedTask.name}] (${editedTask.label}) 修改已保存至工作流 [${pipelineId}]。\n${codeTip}`, stderr: "", exitCode: 0, };