Skip to content

feat(workflow): item 25A 最小 workflow 执行 runtime (CC 2.1.229) - #105

Merged
dahai80 merged 1 commit into
mainfrom
feat/workflow-runtime-item25a
Aug 20, 2026
Merged

feat(workflow): item 25A 最小 workflow 执行 runtime (CC 2.1.229)#105
dahai80 merged 1 commit into
mainfrom
feat/workflow-runtime-item25a

Conversation

@dahai80

@dahai80 dahai80 commented Aug 20, 2026

Copy link
Copy Markdown
Owner

背景

Closes #104

WorkflowTool.execute()纯验证桩——生成 runId、检查 export const meta 存在、写 activeRuns Map、立即返回 status:"started"从不执行脚本。无 parallel()/pipeline()/agent()/phase() runtime。transcriptSubdir 通道全连通但 0 caller。onProgress 接入但被忽略。activeRuns 只写不转 completed/error。

方案 (L-size, 双门禁 default-off)

落地最小可执行 runtime:脚本能跑 agent()/parallel()/pipeline()/phase()/log(),产出结果,runId 传播 transcript + telemetry。

变更

  • src/tools/WorkflowTool/runtime.ts (NEW, ~300 行)
    • executeWorkflow() 入口 + evaluateScript() eval 流水线: export const metaconst __meta__ → 包 async function _w(){...}Bun.Transpiler(loader:ts) 剥 TS 类型 → 拆包 → 花括号平衡抽 meta → new Function(8 params, "return (async()=>{<body>})();")
    • 原语: agent() (runAgent drain → getAssistantMessageText, transcriptSubdir=workflows/<runId>)、parallel()/pipeline() (并发信号量池 min(16,cpu-2), throw→null)、phase()/log()/workflow()(NotImplemented)/budget(stub)
    • isWorkflowRuntimeEnabled() = process.env.FUSION_WORKFLOW_RUNTIME_ENABLED === "1"
  • src/tools/WorkflowTool/WorkflowTool.ts (MODIFY)
    • 双门禁分支: feature("WORKFLOW_SCRIPTS") 编译期 AND FUSION_WORKFLOW_RUNTIME_ENABLED=1 运行期。两层满足才跑 runtime,否则 byte-identical 桩
    • 去下划线接 context/canUseTool/onProgress;activeRuns 转 completed/error;emitPerfettoInstant runId
  • scripts/build.ts: WORKFLOW_SCRIPTS 加入 fullExperimentalFeatures (dev:full 启用)
  • src/__tests__/workflowRuntime.test.ts (NEW, 23 tests): env gate、meta 抽取 (嵌套花括号/字符串含 }/缺 meta 抛错)、eval 顶层 return/await/TS 类型剥除、parallel 并发/throw→null、pipeline 每 item 独立穿 stage、log/phase/budget/workflow-NotImplemented/args 透传/残留 export 抛错

DEFERRED v1

  • schema (agent() 返回纯文本, 记 warn 忽略)
  • 嵌套 workflow() (抛 NotImplemented)
  • budget (stub, 无真实 token 预算)

安全

model-authored 脚本经 new Function 在全局作用域跑。双门禁 (编译+运行) 防护,对齐 CC 自身 Workflow 工具风险接受。完整沙箱超 v1 范围。

验证

  • bun run typecheck — 0 errors
  • bun test src/__tests__/workflowRuntime.test.ts — 23/23 pass
  • bun test src/__tests__/ — 210/210 pass (无回归)
  • bun run build — pass (WORKFLOW_SCRIPTS off → runtime DCE, standard bundle grep workflow_run_started = 0)
  • bun run build:dev:full — pass (WORKFLOW_SCRIPTS on → runtime 入包, dev:full bundle grep workflow_run_started = 2)
  • biome check changed files — 仅 build.ts pre-existing 无关 lint (未触碰)

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

WorkflowTool.execute() 原为纯验证桩,从不执行脚本。落地最小可执行
runtime: agent()/parallel()/pipeline()/phase()/log() 原语 + runId
传播 transcript+telemetry。

- runtime.ts (NEW): executeWorkflow() + evaluateScript() (Bun.Transpiler
  剥 TS → 花括号平衡抽 meta → new Function async IIFE 封装) + 并发信号量
  池 min(16,cpu-2) + isWorkflowRuntimeEnabled()。agent() 用 runAgent
  drain → getAssistantMessageText, transcriptSubdir=workflows/<runId>。
- WorkflowTool.ts: 双门禁分支 feature("WORKFLOW_SCRIPTS") 编译期 AND
  FUSION_WORKFLOW_RUNTIME_ENABLED=1 运行期。去下划线接 context/
  canUseTool/onProgress。activeRuns 转 completed/error。emitPerfettoInstant
  runId。禁用时 byte-identical 桩。
- build.ts: WORKFLOW_SCRIPTS 加入 fullExperimentalFeatures (dev:full 启用)。
- workflowRuntime.test.ts (NEW): 23 单测 (env gate, meta 抽取嵌套/字符串,
  eval 顶层 return/await/TS 剥类型, parallel 并发/throw→null, pipeline,
  log/phase/budget/workflow-NotImplemented/args/残留 export 抛错)。

DEFERRED v1: schema (返回纯文本), 嵌套 workflow() (抛 NotImplemented),
budget (stub)。默认 off, 全 env-gated。

验证: typecheck 0, 23/23 workflowRuntime, 210/210 全套, build+build:dev:full
pass, dev:full bundle 含 runtime, standard bundle DCE runtime。

Closes #104

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dahai80
dahai80 merged commit 5d580d6 into main Aug 20, 2026
1 check passed
@dahai80
dahai80 deleted the feat/workflow-runtime-item25a branch August 20, 2026 15:27
dahai80 added a commit that referenced this pull request Aug 20, 2026
补 item 25A (PR #105) 配套文档 docs/workflow-runtime.md: 双门禁启用法、
脚本契约、原语表、DEFERRED v1 限制、eval 路径、安全注意、runId 传播、
关键文件。

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

item 25A: 最小 workflow 执行 runtime (CC 2.1.229)

1 participant