CLI 参考
@dynamic-workflow/cli 提供三个命令:check(校验)、compile(编译)、run(沙箱运行)。
前置
pnpm install
pnpm build # 构建 packages/*,CLI 入口在 packages/cli/dist/main.js
下文以 flow 代指 node packages/cli/dist/main.js。
flow check
flow check <file.flow>
解析 + 语义 + 类型三层诊断,统一输出格式:
{severity} {code} {line}:{column} {message}
- 无 error 级诊断:输出
✓ <file> checks clean,退出码 0 - 有 error:输出诊断清单与错误数,退出码 1
- info 级诊断(如
external-type)不阻塞,但建议消除—— 把所有被引用的类型都在 workflow 内声明
flow compile
flow compile <file.flow> [--js] [--ir] [--out <path>]
| 选项 | 输出 |
|---|---|
--js(默认) | 受限 JavaScript 胶水代码($runtime ABI) |
--ir | Flow IR(JSON) |
--out <path> | 写入文件而非 stdout |
有 error 级诊断时不产出代码(退出码 1)。编译产物结构:
每个 workflow 对应一个 async function execute_<name>($runtime, $input, $context),
底部 $exports 映射表;agent 调用描述符内联完整 JSON Schema、
timeout 毫秒值与源码 span。
flow run
flow run <file.flow> [--input '<json>' | --input-file <path>]
在沙箱(子进程 + isolate)中执行,使用 FakeAgentRuntime:
按 expect 的 JSON Schema 生成占位输出(字符串字段为常量 "generated")。
flow run examples/simple.flow --input '{"text": "hello"}'
单条目输入
FakeAgentRuntime 的占位值是常量。含跨条目唯一性 require 的示例
(如 unique(items[*].id))请用单条目输入,否则断言会因占位值重复失败。
这不是 bug——它恰好演示了契约校验确实在拦截坏数据。
FakeAgentRuntime 内置演示团队:
engineering-team: main = lead, members = [lead, implementer, test-engineer, reviewer]
退出码
| 命令 | 0 | 非 0 |
|---|---|---|
| check | 无 error 级诊断 | 有 error |
| compile | 编译成功 | 编译失败(有 error) |
| run | 成功,stdout 输出结果 JSON | 输入非法 / 运行时错误(message 到 stderr) |
常见工作流
# 批量校验一个目录
for f in examples/*.flow; do flow check "$f"; done
# 编译全部示例为 JS
mkdir -p examples/dist
for f in examples/*.flow; do
flow compile "$f" --out "examples/dist/$(basename "$f" .flow).js"
done
# 查看 Flow IR(调试 / 学习执行结构)
flow compile examples/delivery.flow --ir | head -50