@tea-agent/loop-agent 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +91 -87
- package/CHANGELOG.md +89 -52
- package/README.md +195 -180
- package/bin/agent-worker.js +22 -0
- package/bin/loop-agent.js +21 -21
- package/dist/application/dag/args.js +6 -0
- package/dist/application/dag/generate-task-dag.js +2 -0
- package/dist/application/dag/run-dag.js +3 -0
- package/dist/application/dag/validate-dag.js +40 -0
- package/dist/cli/command-definitions.js +2 -2
- package/dist/cli/program.js +24 -4
- package/dist/commands/init.js +1011 -459
- package/dist/commands/loop-benchmark.js +11 -11
- package/dist/commands/pi-reuse-benchmark.js +16 -16
- package/dist/executors/cursor-executor.js +1 -1
- package/dist/executors/dag-pi-executor.js +8 -1
- package/dist/task/runtime.js +27 -27
- package/dist/worker/cli.js +119 -0
- package/dist/worker/loop-agent/command-result.js +1 -0
- package/dist/worker/loop-agent/loop-agent-client.js +105 -0
- package/dist/worker/loop-agent/parse-json.js +14 -0
- package/dist/worker/materialize/harness-task-materializer.js +157 -0
- package/dist/worker/pool/failure-routing.js +98 -0
- package/dist/worker/pool/run-store.js +117 -0
- package/dist/worker/pool/types.js +1 -0
- package/dist/worker/preflight.js +108 -0
- package/dist/worker/profile-mapping.js +76 -0
- package/dist/worker/progress-reporter.js +81 -0
- package/dist/worker/report/morning-report.js +69 -0
- package/dist/worker/repos/repo-resolver.js +23 -0
- package/dist/worker/run-task/run-task.js +359 -0
- package/dist/worker/runner/run-ready.js +216 -0
- package/dist/worker/task-graph/acceptance-schema.js +25 -0
- package/dist/worker/task-graph/ready-queue.js +23 -0
- package/dist/worker/task-graph/task-graph-schema.js +28 -0
- package/dist/worker/task-graph/types.js +1 -0
- package/dist/worker/task-graph/validate.js +188 -0
- package/dist/worker/task-spec/complexity-mapping.js +8 -0
- package/dist/worker/task-spec/schema.js +116 -0
- package/dist/worker/task-spec/types.js +1 -0
- package/dist/worker/task-spec/validate.js +352 -0
- package/dist/workflows/dag/canvas-observer.js +275 -275
- package/dist/workflows/dag/dynamic-runtime/loop-until.js +2 -1
- package/dist/workflows/dag/dynamic-runtime/map.js +1 -0
- package/dist/workflows/dag/init-hybrid.js +3 -3
- package/dist/workflows/dag/skills.js +3 -3
- package/dist/workflows/dag/types.js +2 -0
- package/dist/workflows/dynamic/compile.js +11 -0
- package/dist/workflows/dynamic/spec.js +1 -0
- package/docs/README.md +72 -65
- package/docs/agent-dag-recovery-playbook.md +184 -184
- package/docs/agent-dag-runner.md +42 -40
- package/docs/architecture/runtime-boundaries.md +147 -147
- package/docs/cursor-executor-usage.md +25 -25
- package/docs/decisions/README.md +3 -3
- package/docs/design/README.md +36 -36
- package/docs/development-principles.md +73 -71
- package/docs/dynamic-workflow-dag-engine-roadmap.md +1749 -1749
- package/docs/exec-plans/README.md +6 -6
- package/docs/exec-plans/active/README.md +7 -10
- package/docs/exec-plans/completed/README.md +19 -9
- package/docs/feature-workflow.md +186 -186
- package/docs/harness-methodology-debugging.md +153 -153
- package/docs/harness-methodology-tdd.md +130 -130
- package/docs/harness-methodology-verification.md +27 -27
- package/docs/init-surface.manifest.json +175 -0
- package/docs/loop-agent-harness.md +42 -42
- package/docs/production-readiness.md +96 -96
- package/docs/progress/README.md +3 -3
- package/docs/reports/README.md +5 -5
- package/docs/skills/README.md +6 -0
- package/docs/skills/vetted-skill-registry.md +26 -0
- package/docs/templates/adr.md +60 -60
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
- package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -117
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
- package/docs/templates/agent-dag-report.schema.json +454 -454
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
- package/docs/templates/agent-dag.base.json +195 -195
- package/docs/templates/agent-dag.final-verification.json +190 -190
- package/docs/templates/agent-dag.schema.json +316 -316
- package/docs/templates/agent-dag.supervised-implementation.json +500 -500
- package/docs/templates/exec-plan.md +64 -64
- package/docs/templates/feature-spec.md +53 -53
- package/docs/templates/hybrid-dag.json +193 -193
- package/docs/templates/init-evolution-review.md +33 -0
- package/docs/templates/production-readiness-checklist.md +57 -57
- package/docs/templates/progress-log.md +17 -17
- package/docs/templates/project-start-checklist.md +9 -9
- package/docs/templates/qa-report.md +48 -48
- package/docs/templates/sprint-contract.md +29 -29
- package/docs/verification-matrix.md +41 -41
- package/examples/decision-gate-agent-dag.json +123 -123
- package/examples/example-dag.json +51 -51
- package/examples/hybrid-loop-agent-dag.json +194 -194
- package/harness.json +94 -92
- package/package.json +66 -62
- package/skills/ai-engineering-context/SKILL.md +48 -48
- package/skills/code-review-core/SKILL.md +20 -0
- package/skills/codebase-scout/SKILL.md +19 -0
- package/skills/init-capability-evolution/SKILL.md +69 -0
- package/skills/loop-agent/SKILL.md +147 -145
- package/skills/loop-agent/references/README.md +67 -67
- package/skills/loop-agent/references/command-reference.md +403 -357
- package/skills/loop-agent/references/harness-policy.md +259 -258
- package/skills/loop-agent/references/hybrid-dag.md +216 -216
- package/skills/loop-agent/references/learned/README.md +21 -21
- package/skills/loop-agent/references/long-running-loop.md +59 -59
- package/skills/loop-agent/references/model-routing.md +36 -36
- package/skills/loop-agent/references/multi-worktree.md +54 -54
- package/skills/loop-agent/references/one-shot-runs.md +85 -85
- package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -169
- package/skills/loop-agent/references/pi-prompt.md +23 -23
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +81 -81
- package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -44
- package/skills/loop-agent/references/task-workflow.md +84 -84
- package/skills/loop-agent/references/verification-and-failure-handling.md +128 -128
- package/skills/requesting-code-review/SKILL.md +101 -101
- package/skills/requesting-code-review/code-reviewer.md +168 -168
- package/skills/systematic-debugging/CREATION-LOG.md +119 -119
- package/skills/systematic-debugging/SKILL.md +296 -296
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
- package/skills/systematic-debugging/condition-based-waiting.md +115 -115
- package/skills/systematic-debugging/defense-in-depth.md +122 -122
- package/skills/systematic-debugging/find-polluter.sh +63 -63
- package/skills/systematic-debugging/root-cause-tracing.md +169 -169
- package/skills/systematic-debugging/test-academic.md +14 -14
- package/skills/systematic-debugging/test-pressure-1.md +58 -58
- package/skills/systematic-debugging/test-pressure-2.md +68 -68
- package/skills/systematic-debugging/test-pressure-3.md +69 -69
- package/skills/test-driven-development/SKILL.md +20 -0
- package/skills/verification-before-completion/SKILL.md +154 -154
- package/skills/webapp-testing/SKILL.md +19 -0
|
@@ -1,1749 +1,1749 @@
|
|
|
1
|
-
# loop-agent Dynamic Workflow DAG Engine 阶段规划
|
|
2
|
-
|
|
3
|
-
版本:0.2
|
|
4
|
-
日期:2026-07-04
|
|
5
|
-
适用项目:`loop-agent`
|
|
6
|
-
目标读者:项目维护者、实现者、后续接手的 coding agent
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 0. 摘要
|
|
11
|
-
|
|
12
|
-
`loop-agent` 当前已经具备一个较成熟的 **DAG runtime**:它能把 AI coding task 固化为本地任务目录,生成/校验 Agent DAG,调度 Cursor、Pi、shell、static 等 executor,保存 artifacts、logs、decision envelope、report,并以 shell verification 作为完成证据。
|
|
13
|
-
|
|
14
|
-
2026-07-04 复核当前代码后,结论是:
|
|
15
|
-
|
|
16
|
-
> 这个架构方向适合当前项目,但只适合作为 **现有 DAG runtime 上方的逻辑编排/编译层**。
|
|
17
|
-
> 不适合重写 runner,不适合恢复已删除的 Level 1 顺序 fallback,也不适合照搬 Claude Dynamic Workflows 的 JavaScript script 形态。
|
|
18
|
-
|
|
19
|
-
当前更合适的方向是:
|
|
20
|
-
|
|
21
|
-
> 在现有 DAG runtime 上方新增一个 **Dynamic Workflow DAG Engine**。
|
|
22
|
-
> LLM 或 profile 先生成受 schema 约束的 `WorkflowSpec`;engine 对其做校验、风险分析、动态展开和编译;最终产物仍然交给现有 `run-dag` 执行。
|
|
23
|
-
|
|
24
|
-
核心分层:
|
|
25
|
-
|
|
26
|
-
```text
|
|
27
|
-
Loop Task
|
|
28
|
-
管多轮目标、round、signal、context、failureStreak、closeout
|
|
29
|
-
|
|
30
|
-
Dynamic Workflow DAG Engine
|
|
31
|
-
管一次 run 内的动态拆解、map/reduce/verify/condition/loop_until/human_gate
|
|
32
|
-
|
|
33
|
-
DAG runtime
|
|
34
|
-
管 concrete DAG 的 validate、schedule、execute、retry、resume、artifact、report
|
|
35
|
-
|
|
36
|
-
Executors
|
|
37
|
-
Cursor / Pi / shell / static
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
一句话定位:
|
|
41
|
-
|
|
42
|
-
> DAG runtime 解决“如何可靠执行具体 DAG”;Dynamic Workflow DAG Engine 解决“如何把复杂任务动态编译成具体 DAG”;Loop Task 解决“多次 workflow/DAG/shell/review round 如何形成长期目标闭环”。
|
|
43
|
-
|
|
44
|
-
### 0.1 适配性判断
|
|
45
|
-
|
|
46
|
-
| 判断 | 结论 | 原因 |
|
|
47
|
-
|---|---|---|
|
|
48
|
-
| 是否值得做 | 值得,但应分阶段 | 现有 DAG runtime 已经提供 executor、artifact、approval、report、resume 的深 Module,Dynamic Workflow 可以复用这些 leverage |
|
|
49
|
-
| 是否应改 runner 为 JS workflow runtime | 不应 | 任意脚本会削弱 schema 审计、权限分析和 repo governance |
|
|
50
|
-
| 是否应先做自动修代码 workflow | 不应 | 当前最稳的 MVP 是 read-only PR/code review,先验证 fan-out、verifier、reducer |
|
|
51
|
-
| 是否应马上接入 Loop | 不应前置 | Loop 现在已有 `dag` action;workflow action 应在 WorkflowSpec/compile/report 稳定后再接 |
|
|
52
|
-
| 最大技术风险 | runtime expansion | 当前 `run-dag` 基于静态 `DagSpec.tasks` 和 topo ranks;真正动态插入节点需要 runner 层扩展 |
|
|
53
|
-
| 第一优先级 | WorkflowSpec schema + validator + static compiler | 这能先形成可审查 artifact,并证明能编译到现有 `DagSpec` |
|
|
54
|
-
|
|
55
|
-
### 0.2 当前代码对本设计的约束
|
|
56
|
-
|
|
57
|
-
- `DagTask.id` 当前必须是 kebab-case:`/^[a-z][a-z0-9-]*$/`。WorkflowSpec 示例也应使用 kebab-case,或由 compiler 显式维护 workflow id 到 DAG id 的映射。
|
|
58
|
-
- `DagSpec` 目前没有通用 metadata 字段;未知字段不会成为稳定契约。若要保留 `workflowRef`、`workflowNodeId`、compile manifest,应新增明确 schema 字段或使用 sidecar manifest。
|
|
59
|
-
- `run-dag` 当前启动时从完整 `DagSpec.tasks` 计算 topo ranks;Phase 3 以前不应假设 child nodes 能自然“进入 existing scheduler”。
|
|
60
|
-
- DAG 已有 `decisionGate`、`dag approve`、`dag reject`、`dag resume` 和 paused lifecycle。`human_gate` 应优先编译到这套已有机制,而不是发明第二套 approval runtime。
|
|
61
|
-
- `loop` 当前支持 `shell-verify`、`pi-review`、`cursor-fix`、`dag`、`record-round`、`add-signal`、`closeout`;没有 `workflow` action。
|
|
62
|
-
- Level 1 顺序 fallback 已在 `refactor: remove level1 fallback` 后删除;本文档不得再把 `src/workflows/level1/` 描述为保留兼容路径。
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
## 1. 思想来源
|
|
67
|
-
|
|
68
|
-
### 1.1 Claude Dynamic Workflows 的核心启发
|
|
69
|
-
|
|
70
|
-
Claude Code Dynamic Workflows 的官方定义是:Claude 为任务写出一个 JavaScript orchestration script,runtime 在后台执行它;workflow 适用于 codebase audit、大规模 migration、cross-checked research 等超出单轮对话协调能力的任务。官方文档强调,workflow 与 subagents / skills / agent teams 的关键区别不是“能不能多 agent”,而是 **谁持有计划**:subagent 和 agent team 仍由 Claude 或 lead agent 逐轮决定下一步;workflow 由 script 决定下一步,中间状态存在 script variables 中,而不是反复塞回模型上下文。官方文档还明确提到 workflow 可以将 repeatable quality pattern 编码化,例如让独立 agents adversarially review each other’s findings,再进入最终报告。[1]
|
|
71
|
-
|
|
72
|
-
Claude 方案的关键模式:
|
|
73
|
-
|
|
74
|
-
```text
|
|
75
|
-
用户目标
|
|
76
|
-
-> workflow script / runtime 持有计划
|
|
77
|
-
-> fan-out 多个 subagents
|
|
78
|
-
-> 中间结果留在 runtime state
|
|
79
|
-
-> verifier / reducer 过滤、去重、排序
|
|
80
|
-
-> session 只接收最终结果
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
官方文档列出的典型场景包括:
|
|
84
|
-
|
|
85
|
-
- 审计许多文件中的同一类问题。
|
|
86
|
-
- 持续修复直到检查通过。
|
|
87
|
-
- 并行迁移大量文件。
|
|
88
|
-
- Review every changed file and write one summary。
|
|
89
|
-
- 跨多个来源 research 并交叉验证。
|
|
90
|
-
- Find issues until the list stops growing。[1]
|
|
91
|
-
|
|
92
|
-
### 1.2 对 loop-agent 更合适的改造:JS script -> Dynamic DAG IR
|
|
93
|
-
|
|
94
|
-
Claude 的 JS workflow 具有强表达力,但对 `loop-agent` 这种希望产品化、可审计、本地治理的 runtime 来说,JS script 不是最优 IR。更好的方向是:
|
|
95
|
-
|
|
96
|
-
```text
|
|
97
|
-
LLM / profile 生成 WorkflowSpec JSON
|
|
98
|
-
-> schema validator
|
|
99
|
-
-> risk / permission analyzer
|
|
100
|
-
-> compiler / dynamic expander
|
|
101
|
-
-> concrete Agent DAG
|
|
102
|
-
-> existing DAG runtime
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
原因:
|
|
106
|
-
|
|
107
|
-
| 维度 | Claude JS workflow | Dynamic DAG IR |
|
|
108
|
-
|---|---|---|
|
|
109
|
-
| 表达力 | 很强,天然支持 JS loop / branch / variables | 中等,需要 node type 扩展 |
|
|
110
|
-
| 安全审计 | 需要审 JS code | 可以审 schema + primitive |
|
|
111
|
-
| 权限分析 | 较难静态判断 | 容易做 limits / permissions / writeSet 检查 |
|
|
112
|
-
| 可视化 | 脚本不天然图形化 | DAG / logical workflow 天然可视化 |
|
|
113
|
-
| 恢复与重放 | 可以,但依赖 script runtime | 可以基于 run state / artifact ref / compiled DAG 做强恢复 |
|
|
114
|
-
| 产品化 | 面向 Claude Code 内部体验 | 更适合 repo-local CLI + governance |
|
|
115
|
-
|
|
116
|
-
因此,本项目不应追求“复刻 Claude 的 JS script”,而应复刻其操作系统思想:
|
|
117
|
-
|
|
118
|
-
> 编排权离开模型上下文,进入一个可读、可校验、可恢复、可复跑的 workflow artifact。
|
|
119
|
-
|
|
120
|
-
### 1.3 本项目已有思想基础
|
|
121
|
-
|
|
122
|
-
`loop-agent` 当前已经具备以下基础:
|
|
123
|
-
|
|
124
|
-
- repo-local task harness。
|
|
125
|
-
- Agent DAG 编排。
|
|
126
|
-
- DAG validation。
|
|
127
|
-
- DAG report / doctor / recovery recommendation。
|
|
128
|
-
- decision envelope、human approval/rejection、paused/resume lifecycle。
|
|
129
|
-
- supervised DAG convergence pass。
|
|
130
|
-
- Cursor / Pi / shell / static executor registry。
|
|
131
|
-
- `shell-verification` Module,供 DAG shell executor 复用。
|
|
132
|
-
- DAG-oriented task read model。
|
|
133
|
-
- `.harness/` 运行态状态与 artifacts。
|
|
134
|
-
- shell verification 作为完成权威。
|
|
135
|
-
- governance 检查。
|
|
136
|
-
- Loop 长周期 round / signal / closeout 状态机。
|
|
137
|
-
|
|
138
|
-
这些能力说明当前项目已经拥有 Dynamic Workflow 所需的执行内核和治理底座。缺少的不是“再写一个 runtime”,而是上一层的 **WorkflowSpec + workflow validator + risk analyzer + compiler + dynamic expansion + workflow report + workflow/loop integration**。
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## 2. 当前代码现状判断
|
|
143
|
-
|
|
144
|
-
基于当前仓库分析,`loop-agent` 可以被描述为:
|
|
145
|
-
|
|
146
|
-
> 一个 repo-local agent workflow runtime。它为 AI coding agent 提供任务 harness、Agent DAG 编排、Cursor/Pi 执行器集成、确定性 shell 验证、运行证据归档和治理检查,让长期或复杂的 agent 实现工作可以被审查、恢复和交付。
|
|
147
|
-
|
|
148
|
-
本次复核依据的关键代码与文档:
|
|
149
|
-
|
|
150
|
-
- `docs/feature-workflow.md`
|
|
151
|
-
- 源码仓库历史 completed execution plan: remove-level1-fallback
|
|
152
|
-
- `src/workflows/dag/types.ts`
|
|
153
|
-
- `src/workflows/dag/validate.ts`
|
|
154
|
-
- `src/workflows/dag/runner.ts`
|
|
155
|
-
- `src/workflows/dag/lifecycle.ts`
|
|
156
|
-
- `src/workflows/dag/report.ts`
|
|
157
|
-
- `src/workflows/dag/init-hybrid.ts`
|
|
158
|
-
- `src/workflows/loop/actions.ts`
|
|
159
|
-
- `src/commands/loop.ts`
|
|
160
|
-
- `src/commands/dag-run-task.ts`
|
|
161
|
-
- `src/commands/dag-validate.ts`
|
|
162
|
-
- `src/task/read-model.ts`
|
|
163
|
-
- `src/cli/catalog.ts`
|
|
164
|
-
|
|
165
|
-
### 2.1 当前主路径
|
|
166
|
-
|
|
167
|
-
当前主推荐路径已经是 DAG:
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
loop-agent new-task <task-id> "Task title"
|
|
171
|
-
loop-agent dag run-task <task-id> --profile auto --strict-models --output /tmp/<task-id>-dag.json
|
|
172
|
-
loop-agent dag validate --dag /tmp/<task-id>-dag.json --strict-models --strict-governance
|
|
173
|
-
loop-agent run-dag --dag /tmp/<task-id>-dag.json --cwd .
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
主路径语义:
|
|
177
|
-
|
|
178
|
-
| 命令 | 作用 |
|
|
179
|
-
|---|---|
|
|
180
|
-
| `new-task` | 创建 `.harness/tasks/<taskId>` 和 task config/source 结构;legacy workflow state 只作为兼容读输入 |
|
|
181
|
-
| `dag run-task` | 根据任务上下文生成 DAG 草案 |
|
|
182
|
-
| `dag validate` | 校验依赖、写入策略、shell 配置、decision gate、同 rank 写冲突等 |
|
|
183
|
-
| `run-dag` | 执行 DAG,生成 `.harness/dag-runs/<lifecycle>/<runId>` 下的状态、节点 artifacts、报告材料 |
|
|
184
|
-
|
|
185
|
-
### 2.2 当前目录职责
|
|
186
|
-
|
|
187
|
-
| 路径 | 当前职责 | 对 Dynamic Workflow 的意义 |
|
|
188
|
-
|---|---|---|
|
|
189
|
-
| `src/workflows/dag/` | Agent DAG 类型、校验、执行、报告、decision envelope、recovery 建议 | 保留为 concrete DAG runtime 内核 |
|
|
190
|
-
| `src/commands/` | 顶层命令实现,当前命令文件是扁平布局 | 先新增 `dag workflow-*` 子命令实现;稳定后再考虑顶层 `workflow` |
|
|
191
|
-
| `src/task/` | `.harness/tasks/<taskId>` 的 task config、state、artifact、source hash、read model | WorkflowSpec / compiled DAG 可以落在 task 目录下,read model 后续应能暴露 workflow refs |
|
|
192
|
-
| `src/executors/` | Cursor、Pi、shell、static executor 适配 | Dynamic engine 不绕过 executor,只生成节点给 executor 执行 |
|
|
193
|
-
| `src/governance/` | skill safety、repo governance 等规则检查 | 扩展到 workflow-level risk / permission analyzer |
|
|
194
|
-
| `.harness/` | runtime state、tasks、dag-runs、runs、prompts、缓存、live state | 新增 workflow planned/compiled/report state |
|
|
195
|
-
| `src/executors/shell-verification.ts` | shell verification preset、command execution/report/env policy | Workflow command node 应复用这里的 shell 语义 |
|
|
196
|
-
| `src/task/read-model.ts` | DAG-oriented task status / next action 推导 | 后续纳入 workflow planned/compiled/run/report refs |
|
|
197
|
-
|
|
198
|
-
### 2.3 当前 Loop 语义
|
|
199
|
-
|
|
200
|
-
顶层 `loop` 已经是 DAG 之上的长周期任务状态机:
|
|
201
|
-
|
|
202
|
-
```text
|
|
203
|
-
DAG 管一轮怎么执行和验证;
|
|
204
|
-
Loop 管多轮为什么继续、下一步做什么、哪些事实已经验证、何时暂停或收口。
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Loop 当前维护:
|
|
208
|
-
|
|
209
|
-
```text
|
|
210
|
-
.harness/tasks/<taskId>/loop/
|
|
211
|
-
objective.md
|
|
212
|
-
context.md
|
|
213
|
-
state.json
|
|
214
|
-
rounds.jsonl
|
|
215
|
-
signals.jsonl
|
|
216
|
-
events.jsonl
|
|
217
|
-
verification/
|
|
218
|
-
review/
|
|
219
|
-
closeout.md
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Loop state 中已有适合与 Dynamic Workflow 对接的字段:
|
|
223
|
-
|
|
224
|
-
| 字段 | 结合点 |
|
|
225
|
-
|---|---|
|
|
226
|
-
| `openFrontier` | 选择下一轮 workflow profile |
|
|
227
|
-
| `failureStreak` | 决定继续、暂停、升级或换 workflow |
|
|
228
|
-
| `completedCriteria` | 判断 closeout 是否可完成 |
|
|
229
|
-
| `signals.jsonl` | 将 human instruction / approval / scope change 作为 workflow inputs |
|
|
230
|
-
| `rounds.jsonl` | 记录 workflow run ref、report ref、verification summary |
|
|
231
|
-
|
|
232
|
-
### 2.4 当前项目已有优势
|
|
233
|
-
|
|
234
|
-
1. **执行内核已有**:不需要重新实现 executor pool、artifact store、shell verification。
|
|
235
|
-
2. **治理方向正确**:已经强调 shell verification 是完成权威,模型输出不能替代验证。
|
|
236
|
-
3. **DAG lifecycle 已有**:active/paused/completed run 目录、approval/rejection、resume/report 已经是现成底座。
|
|
237
|
-
4. **任务状态正在 DAG 化**:`task-read-model` 已经把 source、DAG draft、DAG run、promotion、closeout 作为主状态面。
|
|
238
|
-
5. **Loop 已能记录长期事实**:适合承接 workflow run 结果,但不应在 MVP 前置。
|
|
239
|
-
6. **测试基础较强**:已有 DAG runner、DAG validate、DAG report、decision gate、executor、task runtime、governance、loop workflow 等测试覆盖。
|
|
240
|
-
|
|
241
|
-
### 2.5 当前主要缺口
|
|
242
|
-
|
|
243
|
-
| 缺口 | 表现 | 需要新增 |
|
|
244
|
-
|---|---|---|
|
|
245
|
-
| 没有 WorkflowSpec IR | 当前 DAG 是 concrete execution graph,不表达 logical primitive | `src/workflows/dynamic/spec.ts` |
|
|
246
|
-
| 没有 workflow-level validator | 现有 validator 只理解 `DagSpec` | `src/workflows/dynamic/validate.ts` |
|
|
247
|
-
| 没有 workflow compiler | 不能从 logical workflow 编译到现有 Agent DAG | `src/workflows/dynamic/compile.ts` |
|
|
248
|
-
| 没有 workflow metadata 保留策略 | `DagSpec` 当前没有稳定 metadata 字段 | `compile manifest` sidecar 或显式扩展 `DagSpec` schema |
|
|
249
|
-
| 没有 dynamic expansion | 静态 DAG 不能自然表达 discover -> map N items;runner ranks 当前启动时固定 | `map_agent` expansion runtime + DAG runner expansion seam |
|
|
250
|
-
| verification 不是一等 workflow pattern | 可以审查,但没有 Finding/Verification 标准 artifact | `verify_agent` + artifact schema |
|
|
251
|
-
| bounded loop 未进入 workflow 层 | 当前 DAG convergence 是固定 supervised chain,不是通用 `loop_until` primitive | `loop_until` bounded expansion |
|
|
252
|
-
| workflow 与 Loop 未打通 | Loop 当前有 `dag` action,但没有 `workflow` action | `loop run --action workflow`,在 compiler/report 稳定后做 |
|
|
253
|
-
| saved workflow/replay 未产品化 | DAG 可保存和 report,但 workflow 复用层还没有 | `.loop-agent/workflows/` / `workflow run` |
|
|
254
|
-
|
|
255
|
-
---
|
|
256
|
-
|
|
257
|
-
## 3. 三层定位:Dynamic Workflow Engine、DAG runtime、Loop Task
|
|
258
|
-
|
|
259
|
-
### 3.1 DAG runtime
|
|
260
|
-
|
|
261
|
-
一句话:
|
|
262
|
-
|
|
263
|
-
> 给我一个 concrete DAG,我负责可靠、安全、可恢复地执行它。
|
|
264
|
-
|
|
265
|
-
职责:
|
|
266
|
-
|
|
267
|
-
- validate concrete DAG。
|
|
268
|
-
- 检查依赖、环、缺失节点、writeSet 冲突、shell config、cwd 越界。
|
|
269
|
-
- 调度 ready nodes。
|
|
270
|
-
- 控制并发、retry、timeout、resume。
|
|
271
|
-
- 调用 Cursor / Pi / shell / static executors。
|
|
272
|
-
- 记录 node artifacts、stdout/stderr、executor result、decision envelope。
|
|
273
|
-
- 生成 DAG report。
|
|
274
|
-
|
|
275
|
-
不负责:
|
|
276
|
-
|
|
277
|
-
- 决定复杂任务要拆成多少动态节点。
|
|
278
|
-
- 根据上游输出生成新的 logical work。
|
|
279
|
-
- 管理多轮目标、用户反馈、长期 lesson。
|
|
280
|
-
|
|
281
|
-
适合场景:
|
|
282
|
-
|
|
283
|
-
- 固定步骤 coding task。
|
|
284
|
-
- 已经生成好的 DAG。
|
|
285
|
-
- 小规模 feature / bug fix。
|
|
286
|
-
- shell verification / deterministic gate。
|
|
287
|
-
|
|
288
|
-
### 3.2 Dynamic Workflow DAG Engine
|
|
289
|
-
|
|
290
|
-
一句话:
|
|
291
|
-
|
|
292
|
-
> 给我一个目标、profile 或 WorkflowSpec,我负责把它动态编排、校验、展开、编译成 concrete DAG。
|
|
293
|
-
|
|
294
|
-
职责:
|
|
295
|
-
|
|
296
|
-
- 定义 `WorkflowSpec` schema。
|
|
297
|
-
- 校验 logical workflow。
|
|
298
|
-
- 做 workflow-level risk / permission analysis。
|
|
299
|
-
- 支持 `agent`、`map_agent`、`verify_agent`、`reduce_agent`、`condition`、`loop_until`、`human_gate`、`artifact_transform`。
|
|
300
|
-
- 根据上游 output 做 dynamic expansion。
|
|
301
|
-
- 将 logical workflow 编译成 runtime 可执行的 concrete DAG。
|
|
302
|
-
- 生成 workflow-level report。
|
|
303
|
-
- 支持 workflow save / inspect / replay。
|
|
304
|
-
|
|
305
|
-
不负责:
|
|
306
|
-
|
|
307
|
-
- 直接执行 shell 或写文件。
|
|
308
|
-
- 跳过现有 DAG runtime 调 executor。
|
|
309
|
-
- 管理跨多轮目标。
|
|
310
|
-
- 改写 completed DAG facts。
|
|
311
|
-
|
|
312
|
-
适合场景:
|
|
313
|
-
|
|
314
|
-
- PR changed files review。
|
|
315
|
-
- codebase-wide audit。
|
|
316
|
-
- 多文件迁移。
|
|
317
|
-
- finding -> independent verifier -> reducer。
|
|
318
|
-
- fix-until-pass 的单 run bounded loop。
|
|
319
|
-
- 多来源 research / cross-check synthesis。
|
|
320
|
-
|
|
321
|
-
### 3.3 Loop Task
|
|
322
|
-
|
|
323
|
-
一句话:
|
|
324
|
-
|
|
325
|
-
> 管一个长期目标跨多轮为什么继续、下一步做什么、哪些事实已验证、何时暂停或 closeout。
|
|
326
|
-
|
|
327
|
-
职责:
|
|
328
|
-
|
|
329
|
-
- 维护 objective、context、state、rounds、signals、closeout。
|
|
330
|
-
- 记录每轮 action / result / verification / lesson / next / decision。
|
|
331
|
-
- 接收 human feedback、approval、scope change。
|
|
332
|
-
- 根据 `openFrontier` 与 `failureStreak` 决定下一轮动作。
|
|
333
|
-
- 汇总多个 workflow/DAG/shell/review run 形成 closeout。
|
|
334
|
-
|
|
335
|
-
不负责:
|
|
336
|
-
|
|
337
|
-
- 执行 node。
|
|
338
|
-
- 展开 map_agent。
|
|
339
|
-
- 校验 workflow schema。
|
|
340
|
-
- 直接修改 DAG run artifacts。
|
|
341
|
-
|
|
342
|
-
适合场景:
|
|
343
|
-
|
|
344
|
-
- 任务跨多轮,单次 DAG 或 workflow 难以完成。
|
|
345
|
-
- 需要保留失败教训和下一步策略。
|
|
346
|
-
- 需要吸收人工反馈、审批、范围变化。
|
|
347
|
-
- 需要把多次 DAG run / workflow run / shell verification 汇总为交付证据。
|
|
348
|
-
|
|
349
|
-
### 3.4 三者关系图
|
|
350
|
-
|
|
351
|
-
```mermaid
|
|
352
|
-
flowchart TD
|
|
353
|
-
U[User Task / Objective] --> T[Task Harness]
|
|
354
|
-
T --> L[Loop Task]
|
|
355
|
-
L -->|chooses bounded action| W[Dynamic Workflow DAG Engine]
|
|
356
|
-
W -->|WorkflowSpec validate / risk / compile / expand| D[Concrete Agent DAG]
|
|
357
|
-
D --> R[DAG runtime]
|
|
358
|
-
R --> E[Cursor / Pi / shell / static executors]
|
|
359
|
-
E --> A[Artifacts / logs / verification / reports]
|
|
360
|
-
A --> R
|
|
361
|
-
R -->|dagRunRef / reportRef| L
|
|
362
|
-
L --> C[Loop closeout]
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
## 4. 目标架构
|
|
368
|
-
|
|
369
|
-
### 4.1 新增模块建议
|
|
370
|
-
|
|
371
|
-
```text
|
|
372
|
-
src/workflows/dynamic/
|
|
373
|
-
spec.ts # WorkflowSpec 类型定义
|
|
374
|
-
schema.ts # JSON schema / zod schema
|
|
375
|
-
validate.ts # logical workflow validator
|
|
376
|
-
risk.ts # workflow-level risk / permission analyzer
|
|
377
|
-
compile.ts # WorkflowSpec -> AgentDAG compiler
|
|
378
|
-
expandMap.ts # map_agent dynamic expansion
|
|
379
|
-
expandLoop.ts # loop_until bounded expansion
|
|
380
|
-
artifactRefs.ts # workflow artifact reference helpers
|
|
381
|
-
artifacts.ts # Finding / Verification / WorkflowReport types
|
|
382
|
-
profiles/
|
|
383
|
-
prReview.ts
|
|
384
|
-
auditAuth.ts
|
|
385
|
-
fixUntilCheckPasses.ts
|
|
386
|
-
report.ts # workflow-level report
|
|
387
|
-
fixtures/
|
|
388
|
-
pr-review.workflow.json
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
命令层:
|
|
392
|
-
|
|
393
|
-
```text
|
|
394
|
-
src/commands/dag-workflow-plan.ts
|
|
395
|
-
src/commands/dag-workflow-validate.ts
|
|
396
|
-
src/commands/dag-workflow-compile.ts
|
|
397
|
-
src/commands/dag-workflow-run.ts # 可选,内部组合 validate + compile + run-dag
|
|
398
|
-
src/commands/workflow-*.ts # 稳定后再提升为顶层 workflow 命令
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
Loop 对接:
|
|
402
|
-
|
|
403
|
-
```text
|
|
404
|
-
src/workflows/loop/actions.ts # 先沿用当前 Loop action 聚合文件
|
|
405
|
-
src/commands/loop.ts # 增加 --action workflow 分派
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
### 4.2 运行态目录建议
|
|
409
|
-
|
|
410
|
-
```text
|
|
411
|
-
.harness/tasks/<taskId>/
|
|
412
|
-
task.json
|
|
413
|
-
|
|
414
|
-
workflows/
|
|
415
|
-
planned/
|
|
416
|
-
pr-review.workflow.json
|
|
417
|
-
validation/
|
|
418
|
-
pr-review.validation.json
|
|
419
|
-
pr-review.risk.json
|
|
420
|
-
compiled/
|
|
421
|
-
pr-review.dag.json
|
|
422
|
-
pr-review.compile-manifest.json
|
|
423
|
-
reports/
|
|
424
|
-
pr-review.workflow-report.md
|
|
425
|
-
|
|
426
|
-
loop/
|
|
427
|
-
objective.md
|
|
428
|
-
context.md
|
|
429
|
-
state.json
|
|
430
|
-
rounds.jsonl
|
|
431
|
-
signals.jsonl
|
|
432
|
-
closeout.md
|
|
433
|
-
|
|
434
|
-
.harness/dag-runs/<lifecycle>/<runId>/
|
|
435
|
-
run.json
|
|
436
|
-
state.json
|
|
437
|
-
<node-id>.json
|
|
438
|
-
<node-id>/
|
|
439
|
-
expansions/
|
|
440
|
-
review-each-file.expansion.json
|
|
441
|
-
verify-findings.expansion.json
|
|
442
|
-
# DAG report is derived by `dag report` from run facts.
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
说明:
|
|
446
|
-
|
|
447
|
-
- `.harness/tasks/<taskId>/workflows/` 保存 workflow 的计划、校验、风险、编译和 workflow-level report,是 task-local artifact。
|
|
448
|
-
- `.harness/dag-runs/<lifecycle>/<runId>/` 仍然保存 concrete DAG run facts,是执行事实源。
|
|
449
|
-
- compiled DAG 应通过 sidecar `compile-manifest.json` 或明确扩展后的 `DagSpec` 字段保留 workflow 来源。不能依赖未知 JSON 字段隐式穿过 `parseDagSpec`。
|
|
450
|
-
- Phase 3 之前,`expansions/` 只是设计目标;当前 runner 不会自动创建这个目录。
|
|
451
|
-
|
|
452
|
-
### 4.3 WorkflowSpec v0.1 草案
|
|
453
|
-
|
|
454
|
-
```json
|
|
455
|
-
{
|
|
456
|
-
"version": "0.1",
|
|
457
|
-
"kind": "dynamic-agent-workflow",
|
|
458
|
-
"meta": {
|
|
459
|
-
"name": "pr-review",
|
|
460
|
-
"description": "Review changed files and produce a ranked summary",
|
|
461
|
-
"riskLevel": "low"
|
|
462
|
-
},
|
|
463
|
-
"inputs": {
|
|
464
|
-
"base": "main",
|
|
465
|
-
"head": "HEAD"
|
|
466
|
-
},
|
|
467
|
-
"limits": {
|
|
468
|
-
"maxConcurrency": 8,
|
|
469
|
-
"maxAgentRuns": 100,
|
|
470
|
-
"maxExpandedNodes": 200,
|
|
471
|
-
"maxRetriesPerNode": 1,
|
|
472
|
-
"maxIterations": 3,
|
|
473
|
-
"maxWallClockMinutes": 30
|
|
474
|
-
},
|
|
475
|
-
"permissions": {
|
|
476
|
-
"filesystem": "read_only",
|
|
477
|
-
"shell": {
|
|
478
|
-
"mode": "allowlist",
|
|
479
|
-
"commands": ["git diff --name-only"]
|
|
480
|
-
},
|
|
481
|
-
"network": "deny",
|
|
482
|
-
"edits": "deny"
|
|
483
|
-
},
|
|
484
|
-
"nodes": [
|
|
485
|
-
{
|
|
486
|
-
"id": "discover-changed-files",
|
|
487
|
-
"type": "command",
|
|
488
|
-
"dependsOn": [],
|
|
489
|
-
"command": "git diff --name-only {{inputs.base}}...{{inputs.head}}",
|
|
490
|
-
"outputSchema": {
|
|
491
|
-
"type": "object",
|
|
492
|
-
"required": ["files"],
|
|
493
|
-
"properties": {
|
|
494
|
-
"files": {
|
|
495
|
-
"type": "array",
|
|
496
|
-
"items": { "type": "string" }
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
"id": "review-each-file",
|
|
503
|
-
"type": "map_agent",
|
|
504
|
-
"dependsOn": ["discover-changed-files"],
|
|
505
|
-
"itemsFrom": "$.nodes['discover-changed-files'].output.files",
|
|
506
|
-
"itemName": "file",
|
|
507
|
-
"concurrency": 8,
|
|
508
|
-
"role": "code-reviewer",
|
|
509
|
-
"prompt": "Review {{file}} for correctness issues. Return concrete findings only.",
|
|
510
|
-
"outputSchema": {
|
|
511
|
-
"type": "object",
|
|
512
|
-
"required": ["file", "findings"],
|
|
513
|
-
"properties": {
|
|
514
|
-
"file": { "type": "string" },
|
|
515
|
-
"findings": { "type": "array" }
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
},
|
|
519
|
-
{
|
|
520
|
-
"id": "verify-findings",
|
|
521
|
-
"type": "verify_agent",
|
|
522
|
-
"dependsOn": ["review-each-file"],
|
|
523
|
-
"itemsFrom": "$.nodes['review-each-file'].output[*].findings[*]",
|
|
524
|
-
"role": "adversarial-verifier",
|
|
525
|
-
"prompt": "Independently verify this finding. Try to refute it. Return verified, refuted, or uncertain.",
|
|
526
|
-
"outputSchema": {
|
|
527
|
-
"type": "object",
|
|
528
|
-
"required": ["findingId", "status", "reason"],
|
|
529
|
-
"properties": {
|
|
530
|
-
"findingId": { "type": "string" },
|
|
531
|
-
"status": { "type": "string", "enum": ["verified", "refuted", "uncertain"] },
|
|
532
|
-
"reason": { "type": "string" }
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
},
|
|
536
|
-
{
|
|
537
|
-
"id": "final-report",
|
|
538
|
-
"type": "reduce_agent",
|
|
539
|
-
"dependsOn": ["verify-findings"],
|
|
540
|
-
"role": "report-writer",
|
|
541
|
-
"prompt": "Create a ranked, deduplicated report. Include verified findings by default; put uncertain findings separately.",
|
|
542
|
-
"outputSchema": {
|
|
543
|
-
"type": "object",
|
|
544
|
-
"required": ["summary", "findings"],
|
|
545
|
-
"properties": {
|
|
546
|
-
"summary": { "type": "string" },
|
|
547
|
-
"findings": { "type": "array" }
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
],
|
|
552
|
-
"final": {
|
|
553
|
-
"from": "final-report"
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
命名约束:
|
|
559
|
-
|
|
560
|
-
- Workflow node id 推荐直接使用 kebab-case,并满足现有 `DagTask.id` 约束。
|
|
561
|
-
- 如果后续允许 workflow node id 比 DAG node id 更宽,compiler 必须产出显式 id mapping,并在 expansion manifest、report、Loop round 中使用同一映射。
|
|
562
|
-
- JSONPath/selector 对 kebab-case id 使用 bracket notation,例如 `$.nodes['review-each-file']...`。
|
|
563
|
-
|
|
564
|
-
### 4.4 核心约束
|
|
565
|
-
|
|
566
|
-
Validator 必须强制:
|
|
567
|
-
|
|
568
|
-
- 每个 workflow 必须有 `version`、`kind`、`nodes`、`final`。
|
|
569
|
-
- 每个 agent-like node 必须有 `outputSchema`。
|
|
570
|
-
- `map_agent` / `verify_agent` 必须有 `itemsFrom`。
|
|
571
|
-
- `command` 必须在 allowlist 内。
|
|
572
|
-
- `loop_until` 必须有 `maxIterations`。
|
|
573
|
-
- 所有 node id 唯一。
|
|
574
|
-
- 所有 dependsOn 指向存在节点。
|
|
575
|
-
- 禁止环,除非通过 `loop_until` 这种 bounded primitive 表达。
|
|
576
|
-
- 禁止 `eval` / arbitrary JS / arbitrary shell。
|
|
577
|
-
- 高风险权限必须要求 `human_gate`。
|
|
578
|
-
- producer 不能 verify 自己的 finding。
|
|
579
|
-
- reducer 默认不能新增 facts,只能 dedupe / rank / group / format。
|
|
580
|
-
- limits 必须存在默认值与硬上限。
|
|
581
|
-
|
|
582
|
-
---
|
|
583
|
-
|
|
584
|
-
## 5. 分阶段落地计划
|
|
585
|
-
|
|
586
|
-
下面的阶段按“每一步都能独立验证”的原则设计。不要一次性实现完整 engine。
|
|
587
|
-
|
|
588
|
-
---
|
|
589
|
-
|
|
590
|
-
## Phase 0:边界与命名收敛
|
|
591
|
-
|
|
592
|
-
### 目标
|
|
593
|
-
|
|
594
|
-
先把概念边界固化,避免后续代码把 `DAG`、`Workflow`、`Loop` 混在一起。
|
|
595
|
-
|
|
596
|
-
### 产物
|
|
597
|
-
|
|
598
|
-
- 将本文档作为 v0.2 roadmap 落到 `docs/`。
|
|
599
|
-
- 新增或更新对象关系图文档:`Task -> WorkflowSpec -> Compiled DAG -> DAG Run -> Loop Round -> Closeout`。
|
|
600
|
-
- CLI help 中明确:
|
|
601
|
-
- `dag` 是 concrete DAG 主路径。
|
|
602
|
-
- `dag workflow-*` 是 logical dynamic workflow 的实验入口。
|
|
603
|
-
- `loop` 是多轮长期控制层。
|
|
604
|
-
- 明确 Level 1 fallback 已删除,不作为 Dynamic Workflow 的实现基础。
|
|
605
|
-
|
|
606
|
-
### 不做
|
|
607
|
-
|
|
608
|
-
- 不改 executor。
|
|
609
|
-
- 不改 DAG runner。
|
|
610
|
-
- 不新增动态展开。
|
|
611
|
-
|
|
612
|
-
### 验证方式
|
|
613
|
-
|
|
614
|
-
```bash
|
|
615
|
-
bash scripts/check-repo.sh
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
### 退出标准
|
|
619
|
-
|
|
620
|
-
- 文档能让新实现者清楚说明三层边界。
|
|
621
|
-
- 没有新增行为风险。
|
|
622
|
-
- 不再把 Loop、Workflow、DAG runner 描述成同一层东西。
|
|
623
|
-
- 不再把 `src/workflows/level1/` 描述成当前可用路径。
|
|
624
|
-
|
|
625
|
-
---
|
|
626
|
-
|
|
627
|
-
## Phase 1:WorkflowSpec schema 与 validator
|
|
628
|
-
|
|
629
|
-
### 目标
|
|
630
|
-
|
|
631
|
-
新增 logical workflow 的类型系统和校验器,但不执行。
|
|
632
|
-
|
|
633
|
-
### 新增代码
|
|
634
|
-
|
|
635
|
-
```text
|
|
636
|
-
src/workflows/dynamic/spec.ts
|
|
637
|
-
src/workflows/dynamic/schema.ts
|
|
638
|
-
src/workflows/dynamic/validate.ts
|
|
639
|
-
src/workflows/dynamic/errors.ts
|
|
640
|
-
src/workflows/dynamic/fixtures/*.workflow.json
|
|
641
|
-
src/commands/dag-workflow-validate.ts
|
|
642
|
-
```
|
|
643
|
-
|
|
644
|
-
### 支持 node types,仅做 schema
|
|
645
|
-
|
|
646
|
-
```text
|
|
647
|
-
agent
|
|
648
|
-
map_agent
|
|
649
|
-
verify_agent
|
|
650
|
-
reduce_agent
|
|
651
|
-
command
|
|
652
|
-
condition
|
|
653
|
-
loop_until
|
|
654
|
-
human_gate
|
|
655
|
-
artifact_transform
|
|
656
|
-
```
|
|
657
|
-
|
|
658
|
-
这些是 WorkflowSpec logical primitive,不等同于现有 `DagTask.executor`。Phase 1 只校验 logical Interface,不把它们直接塞进 `DagSpec.tasks`。
|
|
659
|
-
|
|
660
|
-
Phase 1 不要求全部能执行,只要求能被识别、校验、报错。
|
|
661
|
-
|
|
662
|
-
### CLI
|
|
663
|
-
|
|
664
|
-
```bash
|
|
665
|
-
loop-agent dag workflow-validate \
|
|
666
|
-
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
667
|
-
--strict-governance
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
命令应挂在现有 `dag` 子命令下;不要先新增顶层 `workflow`,避免在 IR 未稳定时扩大公共 Interface。
|
|
671
|
-
|
|
672
|
-
### Validator 规则
|
|
673
|
-
|
|
674
|
-
最低必做:
|
|
675
|
-
|
|
676
|
-
- invalid JSON fail。
|
|
677
|
-
- missing `kind` fail。
|
|
678
|
-
- missing `final` fail。
|
|
679
|
-
- duplicate node id fail。
|
|
680
|
-
- missing dependency fail。
|
|
681
|
-
- unbounded `loop_until` fail。
|
|
682
|
-
- `map_agent` without `itemsFrom` fail。
|
|
683
|
-
- `command` without allowlist fail。
|
|
684
|
-
- agent-like node without `outputSchema` fail。
|
|
685
|
-
- unknown node type fail。
|
|
686
|
-
- unknown permission mode fail。
|
|
687
|
-
- node id 非 kebab-case fail,除非 compiler 已支持显式 id mapping。
|
|
688
|
-
- `itemsFrom` selector 必须只引用已存在上游节点。
|
|
689
|
-
- `permissions.edits != deny` 时必须有 `allowedPaths` / `forbiddenPaths` / `writeSet`。
|
|
690
|
-
- broad write permissions 必须要求 `human_gate` 或编译成现有 DAG decision gate。
|
|
691
|
-
|
|
692
|
-
### 测试
|
|
693
|
-
|
|
694
|
-
```text
|
|
695
|
-
test/dynamic-workflow-validate.test.ts
|
|
696
|
-
valid-pr-review.workflow.json passes
|
|
697
|
-
missing-final.workflow.json fails
|
|
698
|
-
duplicate-node-id.workflow.json fails
|
|
699
|
-
map-without-itemsFrom.workflow.json fails
|
|
700
|
-
command-without-allowlist.workflow.json fails
|
|
701
|
-
loop-without-maxIterations.workflow.json fails
|
|
702
|
-
agent-without-outputSchema.workflow.json fails
|
|
703
|
-
non-kebab-node-id.workflow.json fails
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
### 退出标准
|
|
707
|
-
|
|
708
|
-
- 可以把一个 `WorkflowSpec` 当成可审查 artifact。
|
|
709
|
-
- 错误信息能指出具体 node id 和路径。
|
|
710
|
-
- 不接触 DAG runner,不引入执行风险。
|
|
711
|
-
|
|
712
|
-
---
|
|
713
|
-
|
|
714
|
-
## Phase 2:WorkflowSpec -> AgentDAG compiler v0
|
|
715
|
-
|
|
716
|
-
### 目标
|
|
717
|
-
|
|
718
|
-
证明 logical workflow 可以稳定编译到现有 concrete Agent DAG。
|
|
719
|
-
|
|
720
|
-
### 范围
|
|
721
|
-
|
|
722
|
-
Phase 2 先支持静态可编译 node:
|
|
723
|
-
|
|
724
|
-
```text
|
|
725
|
-
agent
|
|
726
|
-
reduce_agent
|
|
727
|
-
command
|
|
728
|
-
artifact_transform
|
|
729
|
-
human_gate placeholder
|
|
730
|
-
```
|
|
731
|
-
|
|
732
|
-
`map_agent` / `verify_agent` 在 Phase 2 可以先编译成 placeholder/barrier node,或者只支持显式 `items` 的静态展开:
|
|
733
|
-
|
|
734
|
-
```json
|
|
735
|
-
{
|
|
736
|
-
"type": "map_agent",
|
|
737
|
-
"items": ["a.ts", "b.ts"]
|
|
738
|
-
}
|
|
739
|
-
```
|
|
740
|
-
|
|
741
|
-
动态 `itemsFrom` 留到 Phase 3。
|
|
742
|
-
|
|
743
|
-
### 新增代码
|
|
744
|
-
|
|
745
|
-
```text
|
|
746
|
-
src/workflows/dynamic/compile.ts
|
|
747
|
-
src/workflows/dynamic/compileTypes.ts
|
|
748
|
-
src/workflows/dynamic/artifactRefs.ts
|
|
749
|
-
src/commands/dag-workflow-compile.ts
|
|
750
|
-
```
|
|
751
|
-
|
|
752
|
-
### CLI
|
|
753
|
-
|
|
754
|
-
```bash
|
|
755
|
-
loop-agent dag workflow-compile \
|
|
756
|
-
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
757
|
-
--output .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
### 编译规则
|
|
761
|
-
|
|
762
|
-
- 保留 workflow node -> concrete DAG task 映射。
|
|
763
|
-
- 如果 `DagSpec` schema 暂不扩展 origin/metadata 字段,必须写 `compile-manifest.json` sidecar;不要依赖未知字段穿过 `parseDagSpec`。
|
|
764
|
-
- 每个 node 的 `outputSchema` 先转成 `outputContract` 文本或 compile manifest 约束;runtime schema enforcement 可后置。
|
|
765
|
-
- `permissions` 转成 `writePolicy`、`allowedPaths`、`forbiddenPaths`、`writeSet`、shell config 等现有 executor constraints。
|
|
766
|
-
- `limits` 转成 DAG run options、workflow validator hard cap 或 compile manifest;不要假设现有 `DagSpec` 已有全部 limit 字段。
|
|
767
|
-
- `command` 编译成 `executor: "shell"`,并复用现有 `shell` config / allowlist / timeout / cwd 约束。
|
|
768
|
-
- `agent` / `reduce_agent` 编译成 `pi` 或 `static` 节点;read-only profile 先默认 `pi`。
|
|
769
|
-
- `human_gate` 优先编译成现有 DAG `decisionGate` / paused lifecycle;不要新增第二套 approval runtime。
|
|
770
|
-
- `artifact_transform` 在 Phase 2 只允许 deterministic transform;不能引入 stub executor 作为完成实现。
|
|
771
|
-
|
|
772
|
-
### 测试
|
|
773
|
-
|
|
774
|
-
```text
|
|
775
|
-
test/dynamic-workflow-compile.test.ts
|
|
776
|
-
simple workflow compiles to existing AgentDAG shape
|
|
777
|
-
command node preserves allowlist metadata
|
|
778
|
-
reduce node depends on all upstream nodes
|
|
779
|
-
human_gate compiles to existing DAG decision gate semantics
|
|
780
|
-
workflow metadata is preserved in compile manifest or explicit DagSpec field
|
|
781
|
-
```
|
|
782
|
-
|
|
783
|
-
Golden fixture:
|
|
784
|
-
|
|
785
|
-
```text
|
|
786
|
-
test/fixtures/dynamic/simple.workflow.json
|
|
787
|
-
测试输出:test/fixtures/dynamic/simple.compiled-dag.json
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
### 验证命令
|
|
791
|
-
|
|
792
|
-
```bash
|
|
793
|
-
loop-agent dag workflow-validate --workflow test/fixtures/dynamic/simple.workflow.json
|
|
794
|
-
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/simple.workflow.json --output /tmp/simple.dag.json
|
|
795
|
-
loop-agent dag validate --dag /tmp/simple.dag.json --strict-governance
|
|
796
|
-
```
|
|
797
|
-
|
|
798
|
-
### 退出标准
|
|
799
|
-
|
|
800
|
-
- WorkflowSpec 能编译成现有 DAG validator 接受的 DAG。
|
|
801
|
-
- 现有 `run-dag` 不需要大改。
|
|
802
|
-
- 编译产物可 diff、可审查。
|
|
803
|
-
- 编译产物不包含未知 `DagSpec` 字段,或相关字段已经加入 `DagSpec` schema 和 tests。
|
|
804
|
-
|
|
805
|
-
---
|
|
806
|
-
|
|
807
|
-
## Phase 3:Dynamic expansion v0:map_agent
|
|
808
|
-
|
|
809
|
-
### 目标
|
|
810
|
-
|
|
811
|
-
实现真正的 dynamic workflow 核心:
|
|
812
|
-
|
|
813
|
-
```text
|
|
814
|
-
discover targets
|
|
815
|
-
-> map_agent dynamically expands N concrete nodes
|
|
816
|
-
-> reduce_agent fan-in
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
### 设计选择
|
|
820
|
-
|
|
821
|
-
推荐采用 **runtime expansion manifest**,而不是把所有动态能力塞进 planner。
|
|
822
|
-
|
|
823
|
-
当前 `run-dag` 在运行开始时根据 `DagSpec.tasks` 计算固定 ranks。真正的 dynamic expansion 需要新增一个明确的 runner seam,不能只在 compiler 中生成占位节点后假设 scheduler 会自动接收 child nodes。
|
|
824
|
-
|
|
825
|
-
执行到 `map_agent` 时:
|
|
826
|
-
|
|
827
|
-
1. 读取 `itemsFrom` 指向的上游 JSON output。
|
|
828
|
-
2. 校验 items 是 array。
|
|
829
|
-
3. 检查 `maxItems`、`maxExpandedNodes`、`maxAgentRuns`。
|
|
830
|
-
4. 生成 concrete child nodes:
|
|
831
|
-
|
|
832
|
-
```text
|
|
833
|
-
review-each-file-0001
|
|
834
|
-
review-each-file-0002
|
|
835
|
-
review-each-file-0003
|
|
836
|
-
```
|
|
837
|
-
|
|
838
|
-
5. 写入:
|
|
839
|
-
|
|
840
|
-
```text
|
|
841
|
-
.harness/dag-runs/<lifecycle>/<runId>/expansions/review-each-file.expansion.json
|
|
842
|
-
```
|
|
843
|
-
|
|
844
|
-
6. runner 更新 state/ranks 或通过 expansion-aware checkpoint 调度 child nodes。
|
|
845
|
-
7. `map_agent` barrier 在所有 child completed 后 completed。
|
|
846
|
-
|
|
847
|
-
### 新增代码
|
|
848
|
-
|
|
849
|
-
```text
|
|
850
|
-
src/workflows/dynamic/expandMap.ts
|
|
851
|
-
src/workflows/dag/runtimeExpansion.ts # 如果需要在 DAG runner 层接入
|
|
852
|
-
src/workflows/dag/expansionManifest.ts
|
|
853
|
-
```
|
|
854
|
-
|
|
855
|
-
### Expansion manifest 草案
|
|
856
|
-
|
|
857
|
-
```json
|
|
858
|
-
{
|
|
859
|
-
"workflowNodeId": "review-each-file",
|
|
860
|
-
"expandedAt": "2026-07-04T00:00:00.000Z",
|
|
861
|
-
"itemsFrom": "$.nodes['discover-changed-files'].output.files",
|
|
862
|
-
"itemCount": 3,
|
|
863
|
-
"children": [
|
|
864
|
-
{
|
|
865
|
-
"nodeId": "review-each-file-0001",
|
|
866
|
-
"itemRef": "$.items[0]",
|
|
867
|
-
"itemValueHash": "sha256:..."
|
|
868
|
-
}
|
|
869
|
-
]
|
|
870
|
-
}
|
|
871
|
-
```
|
|
872
|
-
|
|
873
|
-
### CLI 验证场景
|
|
874
|
-
|
|
875
|
-
先用 static executor 或 command fixture:
|
|
876
|
-
|
|
877
|
-
```text
|
|
878
|
-
discover-files static output: { "files": ["a.ts", "b.ts"] }
|
|
879
|
-
map_agent review-each-file over files
|
|
880
|
-
reduce_agent final-report
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
命令:
|
|
884
|
-
|
|
885
|
-
```bash
|
|
886
|
-
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/map.workflow.json --output /tmp/map.dag.json
|
|
887
|
-
loop-agent run-dag --dag /tmp/map.dag.json --cwd .
|
|
888
|
-
```
|
|
889
|
-
|
|
890
|
-
### 测试
|
|
891
|
-
|
|
892
|
-
```text
|
|
893
|
-
test/dynamic-workflow-expand-map.test.ts
|
|
894
|
-
expands N children from upstream JSON output
|
|
895
|
-
fails when itemsFrom path missing
|
|
896
|
-
fails when itemsFrom is not array
|
|
897
|
-
respects maxItems
|
|
898
|
-
respects maxExpandedNodes
|
|
899
|
-
writes expansion manifest
|
|
900
|
-
expanded child ids are valid DagTask ids
|
|
901
|
-
resume does not duplicate already-expanded children
|
|
902
|
-
```
|
|
903
|
-
|
|
904
|
-
### 退出标准
|
|
905
|
-
|
|
906
|
-
- 可以跑通 discover -> map -> reduce。
|
|
907
|
-
- resume 不重复生成 child nodes。
|
|
908
|
-
- expansion manifest 可审查。
|
|
909
|
-
- map fan-out 被 limits 约束。
|
|
910
|
-
|
|
911
|
-
---
|
|
912
|
-
|
|
913
|
-
## Phase 4:Finding / Verification / Reducer 标准 artifact
|
|
914
|
-
|
|
915
|
-
### 目标
|
|
916
|
-
|
|
917
|
-
把 Claude Dynamic Workflows 中最有价值的质量模式一等化:
|
|
918
|
-
|
|
919
|
-
```text
|
|
920
|
-
producer -> finding
|
|
921
|
-
finding -> independent verifier
|
|
922
|
-
verified finding -> reducer
|
|
923
|
-
```
|
|
924
|
-
|
|
925
|
-
### 新增标准 artifact
|
|
926
|
-
|
|
927
|
-
```ts
|
|
928
|
-
type Finding = {
|
|
929
|
-
id: string
|
|
930
|
-
sourceNodeId: string
|
|
931
|
-
targetRef: string
|
|
932
|
-
title: string
|
|
933
|
-
severity: 'low' | 'medium' | 'high' | 'critical'
|
|
934
|
-
evidence: EvidenceRef[]
|
|
935
|
-
recommendation: string
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
type Verification = {
|
|
939
|
-
findingId: string
|
|
940
|
-
verifierNodeId: string
|
|
941
|
-
status: 'verified' | 'refuted' | 'uncertain'
|
|
942
|
-
reason: string
|
|
943
|
-
evidence: EvidenceRef[]
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
type WorkflowReport = {
|
|
947
|
-
summary: string
|
|
948
|
-
verifiedFindings: Finding[]
|
|
949
|
-
uncertainFindings: Finding[]
|
|
950
|
-
refutedFindingsRef?: ArtifactRef
|
|
951
|
-
evidenceRefs: ArtifactRef[]
|
|
952
|
-
}
|
|
953
|
-
```
|
|
954
|
-
|
|
955
|
-
### 新增 node semantics
|
|
956
|
-
|
|
957
|
-
```text
|
|
958
|
-
verify_agent:
|
|
959
|
-
- 本质是受约束的 map_agent
|
|
960
|
-
- itemsFrom 通常指向 findings
|
|
961
|
-
- verifier 不能是 producer node
|
|
962
|
-
- verifier prompt 只能看到 finding + evidence + target artifact
|
|
963
|
-
- verifier 不看 producer chain-of-thought
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
```text
|
|
967
|
-
reduce_agent:
|
|
968
|
-
- 只做 dedupe / rank / group / format
|
|
969
|
-
- 默认不能新增事实发现
|
|
970
|
-
- final report 默认只包含 verified findings
|
|
971
|
-
- uncertain findings 单列
|
|
972
|
-
- refuted findings 只进入 appendix / trace
|
|
973
|
-
```
|
|
974
|
-
|
|
975
|
-
### 内置 profile:`pr-review`
|
|
976
|
-
|
|
977
|
-
第一条真实可演示 workflow:
|
|
978
|
-
|
|
979
|
-
```text
|
|
980
|
-
discover-changed-files
|
|
981
|
-
-> map_agent(review-each-file)
|
|
982
|
-
-> verify_agent(verify-each-finding)
|
|
983
|
-
-> reduce_agent(final-ranked-summary)
|
|
984
|
-
```
|
|
985
|
-
|
|
986
|
-
CLI:
|
|
987
|
-
|
|
988
|
-
```bash
|
|
989
|
-
loop-agent dag workflow-plan <taskId> --profile pr-review \
|
|
990
|
-
--output .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json
|
|
991
|
-
|
|
992
|
-
loop-agent dag workflow-validate \
|
|
993
|
-
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
994
|
-
--strict-governance
|
|
995
|
-
|
|
996
|
-
loop-agent dag workflow-compile \
|
|
997
|
-
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
998
|
-
--output .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json
|
|
999
|
-
|
|
1000
|
-
loop-agent run-dag \
|
|
1001
|
-
--dag .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json \
|
|
1002
|
-
--cwd .
|
|
1003
|
-
```
|
|
1004
|
-
|
|
1005
|
-
### 测试
|
|
1006
|
-
|
|
1007
|
-
```text
|
|
1008
|
-
test/dynamic-workflow-verification.test.ts
|
|
1009
|
-
verify_agent expands per finding
|
|
1010
|
-
producer cannot verify own finding
|
|
1011
|
-
verified/refuted/uncertain statuses are preserved
|
|
1012
|
-
reducer includes only verified findings by default
|
|
1013
|
-
uncertain findings are separated
|
|
1014
|
-
refuted findings are excluded from main report
|
|
1015
|
-
```
|
|
1016
|
-
|
|
1017
|
-
### 退出标准
|
|
1018
|
-
|
|
1019
|
-
- `pr-review` profile 能在 fixture repo 或 static executor 下跑通。
|
|
1020
|
-
- final report 能体现 verified / uncertain / refuted 分层。
|
|
1021
|
-
- reducer 不新增未验证 fact。
|
|
1022
|
-
|
|
1023
|
-
---
|
|
1024
|
-
|
|
1025
|
-
## Phase 5:Dynamic Workflow 与 Loop Task 打通
|
|
1026
|
-
|
|
1027
|
-
### 目标
|
|
1028
|
-
|
|
1029
|
-
让 Dynamic Workflow 成为 Loop 的一种 bounded action。
|
|
1030
|
-
|
|
1031
|
-
当前 Loop 已有:
|
|
1032
|
-
|
|
1033
|
-
```text
|
|
1034
|
-
loop run --action shell-verify
|
|
1035
|
-
loop run --action pi-review
|
|
1036
|
-
loop run --action cursor-fix
|
|
1037
|
-
loop run --action dag [--execute]
|
|
1038
|
-
```
|
|
1039
|
-
|
|
1040
|
-
新增:
|
|
1041
|
-
|
|
1042
|
-
```bash
|
|
1043
|
-
loop-agent loop run <taskId> --action workflow --profile pr-review --execute
|
|
1044
|
-
```
|
|
1045
|
-
|
|
1046
|
-
或:
|
|
1047
|
-
|
|
1048
|
-
```bash
|
|
1049
|
-
loop-agent loop run <taskId> \
|
|
1050
|
-
--action workflow \
|
|
1051
|
-
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
1052
|
-
--execute
|
|
1053
|
-
```
|
|
1054
|
-
|
|
1055
|
-
### Loop round 记录格式
|
|
1056
|
-
|
|
1057
|
-
```json
|
|
1058
|
-
{
|
|
1059
|
-
"round": 4,
|
|
1060
|
-
"action": "workflow",
|
|
1061
|
-
"workflow": "pr-review",
|
|
1062
|
-
"workflowRef": ".harness/tasks/T/workflows/planned/pr-review.workflow.json",
|
|
1063
|
-
"compiledDagRef": ".harness/tasks/T/workflows/compiled/pr-review.dag.json",
|
|
1064
|
-
"compileManifestRef": ".harness/tasks/T/workflows/compiled/pr-review.compile-manifest.json",
|
|
1065
|
-
"runRef": ".harness/dag-runs/<lifecycle>/run-123",
|
|
1066
|
-
"reportRef": ".harness/tasks/T/workflows/reports/pr-review.workflow-report.md",
|
|
1067
|
-
"result": "Reviewed 17 changed files; produced 8 findings.",
|
|
1068
|
-
"verification": "5 verified, 2 refuted, 1 uncertain.",
|
|
1069
|
-
"lesson": "Most issues are concentrated in CLI routing.",
|
|
1070
|
-
"next": "Fix verified high severity findings.",
|
|
1071
|
-
"decision": "continue"
|
|
1072
|
-
}
|
|
1073
|
-
```
|
|
1074
|
-
|
|
1075
|
-
### Loop context 更新原则
|
|
1076
|
-
|
|
1077
|
-
Loop `context.md` 只吸收高层事实,不复制全部 node outputs:
|
|
1078
|
-
|
|
1079
|
-
```text
|
|
1080
|
-
已验证事实:
|
|
1081
|
-
- pr-review workflow scanned 17 files.
|
|
1082
|
-
- 5 findings verified.
|
|
1083
|
-
- 1 finding uncertain.
|
|
1084
|
-
- no code edits were made.
|
|
1085
|
-
|
|
1086
|
-
下一步:
|
|
1087
|
-
- run fix-verified-findings workflow after human approval.
|
|
1088
|
-
```
|
|
1089
|
-
|
|
1090
|
-
### signals -> workflow inputs
|
|
1091
|
-
|
|
1092
|
-
`signals.jsonl` 中的人工反馈应成为 workflow inputs:
|
|
1093
|
-
|
|
1094
|
-
```json
|
|
1095
|
-
{
|
|
1096
|
-
"severityFilter": ["high", "critical"],
|
|
1097
|
-
"forbiddenPaths": ["billing/**"],
|
|
1098
|
-
"humanInstructionsRef": ".harness/tasks/T/loop/signals.jsonl"
|
|
1099
|
-
}
|
|
1100
|
-
```
|
|
1101
|
-
|
|
1102
|
-
### 测试
|
|
1103
|
-
|
|
1104
|
-
```text
|
|
1105
|
-
test/loop-workflow-action.test.ts
|
|
1106
|
-
loop workflow action records workflowRef/runRef/reportRef
|
|
1107
|
-
loop context updates from workflow summary
|
|
1108
|
-
loop does not rewrite DAG run artifacts
|
|
1109
|
-
loop closeout includes workflow evidence
|
|
1110
|
-
loop --auto can choose workflow from openFrontier
|
|
1111
|
-
```
|
|
1112
|
-
|
|
1113
|
-
### 退出标准
|
|
1114
|
-
|
|
1115
|
-
- Loop 可以运行 workflow action。
|
|
1116
|
-
- Workflow run facts 以 ref 形式进入 `rounds.jsonl`。
|
|
1117
|
-
- `loop closeout` 能引用 workflow evidence。
|
|
1118
|
-
- Loop 不直接改写 completed DAG facts。
|
|
1119
|
-
|
|
1120
|
-
---
|
|
1121
|
-
|
|
1122
|
-
## Phase 6:condition 与 loop_until
|
|
1123
|
-
|
|
1124
|
-
### 目标
|
|
1125
|
-
|
|
1126
|
-
支持单次 workflow 内的 bounded dynamic control。
|
|
1127
|
-
|
|
1128
|
-
### condition
|
|
1129
|
-
|
|
1130
|
-
`condition` 根据结构化 output 决定边:
|
|
1131
|
-
|
|
1132
|
-
```json
|
|
1133
|
-
{
|
|
1134
|
-
"id": "choose-next",
|
|
1135
|
-
"type": "condition",
|
|
1136
|
-
"dependsOn": ["run-typecheck"],
|
|
1137
|
-
"cases": [
|
|
1138
|
-
{
|
|
1139
|
-
"when": "$.nodes['run-typecheck'].output.status == 'passed'",
|
|
1140
|
-
"then": "final-report"
|
|
1141
|
-
},
|
|
1142
|
-
{
|
|
1143
|
-
"when": "$.nodes['run-typecheck'].output.status == 'failed'",
|
|
1144
|
-
"then": "analyze-errors"
|
|
1145
|
-
}
|
|
1146
|
-
],
|
|
1147
|
-
"default": "human-gate"
|
|
1148
|
-
}
|
|
1149
|
-
```
|
|
1150
|
-
|
|
1151
|
-
### loop_until
|
|
1152
|
-
|
|
1153
|
-
`loop_until` 必须 bounded:
|
|
1154
|
-
|
|
1155
|
-
```json
|
|
1156
|
-
{
|
|
1157
|
-
"id": "fix-until-tsc-passes",
|
|
1158
|
-
"type": "loop_until",
|
|
1159
|
-
"maxIterations": 5,
|
|
1160
|
-
"stopWhen": {
|
|
1161
|
-
"any": [
|
|
1162
|
-
"$.last.output.status == 'passed'",
|
|
1163
|
-
"$.stagnation.rounds >= 2"
|
|
1164
|
-
]
|
|
1165
|
-
},
|
|
1166
|
-
"body": [
|
|
1167
|
-
{ "id": "analyze-errors", "type": "agent" },
|
|
1168
|
-
{ "id": "apply-fixes", "type": "agent" },
|
|
1169
|
-
{ "id": "rerun-tsc", "type": "command" }
|
|
1170
|
-
]
|
|
1171
|
-
}
|
|
1172
|
-
```
|
|
1173
|
-
|
|
1174
|
-
实现建议:
|
|
1175
|
-
|
|
1176
|
-
```text
|
|
1177
|
-
不要允许真正无限环。
|
|
1178
|
-
编译时或 runtime expansion 时展开成最多 N 轮:
|
|
1179
|
-
round_1 -> condition_1 -> round_2 -> condition_2 -> ... -> round_N
|
|
1180
|
-
```
|
|
1181
|
-
|
|
1182
|
-
### 内置 profile
|
|
1183
|
-
|
|
1184
|
-
```text
|
|
1185
|
-
fix-until-check-passes
|
|
1186
|
-
```
|
|
1187
|
-
|
|
1188
|
-
流程:
|
|
1189
|
-
|
|
1190
|
-
```text
|
|
1191
|
-
run-check
|
|
1192
|
-
-> loop_until(maxIterations=3)
|
|
1193
|
-
analyze-errors
|
|
1194
|
-
apply-bounded-fix
|
|
1195
|
-
rerun-check
|
|
1196
|
-
-> final-report
|
|
1197
|
-
```
|
|
1198
|
-
|
|
1199
|
-
### 测试
|
|
1200
|
-
|
|
1201
|
-
```text
|
|
1202
|
-
test/dynamic-workflow-condition.test.ts
|
|
1203
|
-
test/dynamic-workflow-loop-until.test.ts
|
|
1204
|
-
condition follows expected branch
|
|
1205
|
-
condition uses default branch on no match
|
|
1206
|
-
loop_until stops on passed status
|
|
1207
|
-
loop_until stops on maxIterations
|
|
1208
|
-
loop_until detects no-progress sentinel
|
|
1209
|
-
loop_until fails validation without maxIterations
|
|
1210
|
-
```
|
|
1211
|
-
|
|
1212
|
-
### 退出标准
|
|
1213
|
-
|
|
1214
|
-
- bounded loop 可以跑 shell/static fixture。
|
|
1215
|
-
- 没有任何 unbounded cycle 能通过 validator。
|
|
1216
|
-
- loop_until 结果能进入 DAG report 与 workflow report。
|
|
1217
|
-
|
|
1218
|
-
---
|
|
1219
|
-
|
|
1220
|
-
## Phase 7:human_gate、approval、pause/resume
|
|
1221
|
-
|
|
1222
|
-
### 目标
|
|
1223
|
-
|
|
1224
|
-
把高风险 workflow 的审批点纳入 runtime,而不是依靠 prompt 约定。
|
|
1225
|
-
|
|
1226
|
-
### human_gate 语义
|
|
1227
|
-
|
|
1228
|
-
```json
|
|
1229
|
-
{
|
|
1230
|
-
"id": "approve-auth-edits",
|
|
1231
|
-
"type": "human_gate",
|
|
1232
|
-
"dependsOn": ["plan-auth-changes"],
|
|
1233
|
-
"reason": "Auth middleware edits require explicit approval",
|
|
1234
|
-
"approvalSchema": {
|
|
1235
|
-
"type": "object",
|
|
1236
|
-
"required": ["approved", "scope"],
|
|
1237
|
-
"properties": {
|
|
1238
|
-
"approved": { "type": "boolean" },
|
|
1239
|
-
"scope": { "type": "array", "items": { "type": "string" } }
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
```
|
|
1244
|
-
|
|
1245
|
-
### 命令
|
|
1246
|
-
|
|
1247
|
-
当前仓库已经有 DAG approval 命令;`human_gate` 应编译到这套机制:
|
|
1248
|
-
|
|
1249
|
-
```bash
|
|
1250
|
-
loop-agent dag approve --run-id <runId> --option <option-id> [--notes <text>]
|
|
1251
|
-
loop-agent dag reject --run-id <runId> --reason "Need manual review"
|
|
1252
|
-
loop-agent dag resume --run-id <runId>
|
|
1253
|
-
```
|
|
1254
|
-
|
|
1255
|
-
Loop integration:
|
|
1256
|
-
|
|
1257
|
-
```bash
|
|
1258
|
-
loop-agent loop add-signal <taskId> --type approval --message "Approved high severity auth fixes"
|
|
1259
|
-
loop-agent loop run <taskId> --auto
|
|
1260
|
-
```
|
|
1261
|
-
|
|
1262
|
-
### 测试
|
|
1263
|
-
|
|
1264
|
-
```text
|
|
1265
|
-
test/dynamic-workflow-human-gate.test.ts
|
|
1266
|
-
human_gate pauses run
|
|
1267
|
-
approval resumes descendants
|
|
1268
|
-
rejection marks workflow blocked
|
|
1269
|
-
loop signal can satisfy pending gate
|
|
1270
|
-
```
|
|
1271
|
-
|
|
1272
|
-
### 退出标准
|
|
1273
|
-
|
|
1274
|
-
- 高风险 workflow 可以在 gate 暂停。
|
|
1275
|
-
- approval/rejection 都进入 audit trail。
|
|
1276
|
-
- Loop 能记录 pending approval 并 resume。
|
|
1277
|
-
|
|
1278
|
-
---
|
|
1279
|
-
|
|
1280
|
-
## Phase 8:saved workflows、replay、operator UX
|
|
1281
|
-
|
|
1282
|
-
### 目标
|
|
1283
|
-
|
|
1284
|
-
把 workflow 从一次性 plan 变成可复用、可 diff、可 replay 的产品能力。
|
|
1285
|
-
|
|
1286
|
-
### 保存位置
|
|
1287
|
-
|
|
1288
|
-
```text
|
|
1289
|
-
.loop-agent/workflows/ # repo shared
|
|
1290
|
-
~/.loop-agent/workflows/ # personal
|
|
1291
|
-
.harness/tasks/<taskId>/workflows/ # task-local generated plans
|
|
1292
|
-
```
|
|
1293
|
-
|
|
1294
|
-
### 命令
|
|
1295
|
-
|
|
1296
|
-
```bash
|
|
1297
|
-
loop-agent workflow list
|
|
1298
|
-
loop-agent workflow inspect pr-review
|
|
1299
|
-
loop-agent workflow run pr-review --args '{"base":"main","head":"HEAD"}'
|
|
1300
|
-
loop-agent workflow save --from .harness/tasks/T/workflows/planned/pr-review.workflow.json --name pr-review
|
|
1301
|
-
loop-agent workflow diff pr-review --against .harness/tasks/T/workflows/planned/pr-review.workflow.json
|
|
1302
|
-
loop-agent workflow replay <runId>
|
|
1303
|
-
```
|
|
1304
|
-
|
|
1305
|
-
DAG operator UX:
|
|
1306
|
-
|
|
1307
|
-
```bash
|
|
1308
|
-
loop-agent dag status --run-id <runId>
|
|
1309
|
-
loop-agent dag doctor
|
|
1310
|
-
loop-agent dag report --run-id <runId> --json --lifecycle all
|
|
1311
|
-
loop-agent dag decision inspect --run-id <runId>
|
|
1312
|
-
loop-agent dag decision validate --run-id <runId>
|
|
1313
|
-
loop-agent dag resume --run-id <runId>
|
|
1314
|
-
```
|
|
1315
|
-
|
|
1316
|
-
未来如果需要更细粒度 operator UX,再新增 `inspect-node`、`restart-node`、`stop` 等命令;不要在 saved workflow 阶段顺手扩大 DAG control plane。
|
|
1317
|
-
|
|
1318
|
-
### 测试
|
|
1319
|
-
|
|
1320
|
-
```text
|
|
1321
|
-
test/workflow-list.test.ts
|
|
1322
|
-
test/workflow-run.test.ts
|
|
1323
|
-
test/workflow-save.test.ts
|
|
1324
|
-
test/workflow-replay.test.ts
|
|
1325
|
-
test/dag-operator-status.test.ts
|
|
1326
|
-
```
|
|
1327
|
-
|
|
1328
|
-
### 退出标准
|
|
1329
|
-
|
|
1330
|
-
- workflow 可保存、可复用、可传 args。
|
|
1331
|
-
- replay 不重复已完成 artifacts,或明确说明哪些节点重新执行。
|
|
1332
|
-
- operator 能定位失败 node、查看 expansion、查看 verifier 结果。
|
|
1333
|
-
|
|
1334
|
-
---
|
|
1335
|
-
|
|
1336
|
-
## Phase 9:大规模迁移与 worktree/shard execution
|
|
1337
|
-
|
|
1338
|
-
### 目标
|
|
1339
|
-
|
|
1340
|
-
支持更高风险、更高价值的场景:多文件 migration。
|
|
1341
|
-
|
|
1342
|
-
### 原则
|
|
1343
|
-
|
|
1344
|
-
- 不允许多个 writer agent 在同一工作树无隔离并发写。
|
|
1345
|
-
- 使用 shard / worktree / delegate / harvest 模式。
|
|
1346
|
-
- 每个 shard 有独立 verification。
|
|
1347
|
-
- merge patch 前做 conflict 和 test gate。
|
|
1348
|
-
|
|
1349
|
-
### Workflow pattern
|
|
1350
|
-
|
|
1351
|
-
```text
|
|
1352
|
-
discover-targets
|
|
1353
|
-
-> shard-targets
|
|
1354
|
-
-> map_agent(migrate-shard-in-isolated-worktree)
|
|
1355
|
-
-> map_agent(verify-shard)
|
|
1356
|
-
-> reduce_agent(merge-plan)
|
|
1357
|
-
-> human_gate(approve-merge)
|
|
1358
|
-
-> apply-merge
|
|
1359
|
-
-> final-shell-verify
|
|
1360
|
-
```
|
|
1361
|
-
|
|
1362
|
-
### 测试
|
|
1363
|
-
|
|
1364
|
-
```text
|
|
1365
|
-
test/dynamic-workflow-sharded-migration.test.ts
|
|
1366
|
-
writeSet conflicts rejected
|
|
1367
|
-
shards get isolated workspaces
|
|
1368
|
-
failed shard does not block successful shard artifacts
|
|
1369
|
-
merge requires human_gate when writeSet is broad
|
|
1370
|
-
```
|
|
1371
|
-
|
|
1372
|
-
### 退出标准
|
|
1373
|
-
|
|
1374
|
-
- 可以安全 dogfood 一个低风险 repo migration。
|
|
1375
|
-
- 每个 shard 的 patch、verification、failure reason 独立可追踪。
|
|
1376
|
-
- 最终 merge 有明确 approval 和 shell verification。
|
|
1377
|
-
|
|
1378
|
-
---
|
|
1379
|
-
|
|
1380
|
-
## 6. 建议 MVP 顺序
|
|
1381
|
-
|
|
1382
|
-
不要先做自动修代码。MVP 应分成两层:
|
|
1383
|
-
|
|
1384
|
-
1. **工程 MVP**:`WorkflowSpec -> validate -> compile -> dag validate`,不要求 runtime dynamic expansion。
|
|
1385
|
-
2. **产品 MVP**:read-only PR review,因为它最能展示 Dynamic Workflow 的价值,同时风险低。
|
|
1386
|
-
|
|
1387
|
-
这样安排的原因是:当前 `run-dag` 还没有动态插入节点的 seam。先做工程 MVP 可以验证 Interface 和 compiler depth,再进入 map/verify/reduce 的产品 MVP。
|
|
1388
|
-
|
|
1389
|
-
### 6.1 工程 MVP:static workflow compile
|
|
1390
|
-
|
|
1391
|
-
目标:
|
|
1392
|
-
|
|
1393
|
-
```text
|
|
1394
|
-
simple-readonly-workflow.workflow.json
|
|
1395
|
-
-> dag workflow-validate
|
|
1396
|
-
-> dag workflow-compile
|
|
1397
|
-
-> dag validate --strict-governance
|
|
1398
|
-
```
|
|
1399
|
-
|
|
1400
|
-
验收:
|
|
1401
|
-
|
|
1402
|
-
```bash
|
|
1403
|
-
loop-agent dag workflow-validate --workflow test/fixtures/dynamic/simple-readonly.workflow.json --strict-governance
|
|
1404
|
-
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/simple-readonly.workflow.json --output /tmp/simple-readonly.dag.json
|
|
1405
|
-
loop-agent dag validate --dag /tmp/simple-readonly.dag.json --strict-models --strict-governance
|
|
1406
|
-
```
|
|
1407
|
-
|
|
1408
|
-
退出标准:
|
|
1409
|
-
|
|
1410
|
-
- 不改 `run-dag`。
|
|
1411
|
-
- 编译产物通过现有 DAG validator。
|
|
1412
|
-
- compile manifest 能解释每个 workflow node 对应哪个 DAG task。
|
|
1413
|
-
|
|
1414
|
-
### 6.2 产品 MVP:PR Review Workflow
|
|
1415
|
-
|
|
1416
|
-
MVP workflow:
|
|
1417
|
-
|
|
1418
|
-
```text
|
|
1419
|
-
discover-changed-files
|
|
1420
|
-
-> map_agent(review-each-file)
|
|
1421
|
-
-> verify_agent(verify-each-finding)
|
|
1422
|
-
-> reduce_agent(final-ranked-summary)
|
|
1423
|
-
```
|
|
1424
|
-
|
|
1425
|
-
### 为什么选它
|
|
1426
|
-
|
|
1427
|
-
- 文件数量运行时才知道,能验证 dynamic expansion。
|
|
1428
|
-
- findings 数量运行时才知道,能验证 second-order expansion。
|
|
1429
|
-
- verifier/reducer 能展示质量闭环。
|
|
1430
|
-
- read-only,风险低。
|
|
1431
|
-
- 最终 report 容易人工评估。
|
|
1432
|
-
- 可后续接 Loop:如果有 verified high severity findings,下一轮再进入 fix workflow。
|
|
1433
|
-
- read-only PR review 不要求 writer concurrency,因此不会先触发多 writer/worktree 风险。
|
|
1434
|
-
|
|
1435
|
-
### MVP 验收
|
|
1436
|
-
|
|
1437
|
-
```bash
|
|
1438
|
-
loop-agent new-task pr-review-demo "Review changed files"
|
|
1439
|
-
loop-agent dag workflow-plan pr-review-demo --profile pr-review --output .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json
|
|
1440
|
-
loop-agent dag workflow-validate --workflow .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json --strict-governance
|
|
1441
|
-
loop-agent dag workflow-compile --workflow .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json --output .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json
|
|
1442
|
-
loop-agent dag validate --dag .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json --strict-governance
|
|
1443
|
-
loop-agent run-dag --dag .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json --cwd .
|
|
1444
|
-
```
|
|
1445
|
-
|
|
1446
|
-
验收结果:
|
|
1447
|
-
|
|
1448
|
-
- `.harness/dag-runs/.../expansions/review-each-file.expansion.json` 存在。
|
|
1449
|
-
- `.harness/dag-runs/.../expansions/verify-findings.expansion.json` 存在。
|
|
1450
|
-
- final report 区分 verified / uncertain / refuted。
|
|
1451
|
-
- run-dag report 可引用到每个 verifier artifact。
|
|
1452
|
-
- workflow-level report 可复制给用户。
|
|
1453
|
-
|
|
1454
|
-
---
|
|
1455
|
-
|
|
1456
|
-
## 7. 测试与验证金字塔
|
|
1457
|
-
|
|
1458
|
-
### 7.1 Unit tests
|
|
1459
|
-
|
|
1460
|
-
```text
|
|
1461
|
-
WorkflowSpec parser
|
|
1462
|
-
schema validation
|
|
1463
|
-
risk analyzer
|
|
1464
|
-
JSONPath itemsFrom resolver
|
|
1465
|
-
map expansion
|
|
1466
|
-
loop_until expansion
|
|
1467
|
-
artifact ref resolver
|
|
1468
|
-
Finding / Verification schema
|
|
1469
|
-
```
|
|
1470
|
-
|
|
1471
|
-
### 7.2 Golden tests
|
|
1472
|
-
|
|
1473
|
-
输入:
|
|
1474
|
-
|
|
1475
|
-
```text
|
|
1476
|
-
*.workflow.json
|
|
1477
|
-
```
|
|
1478
|
-
|
|
1479
|
-
输出:
|
|
1480
|
-
|
|
1481
|
-
```text
|
|
1482
|
-
*.compiled-dag.json
|
|
1483
|
-
*.validation.json
|
|
1484
|
-
*.risk.json
|
|
1485
|
-
```
|
|
1486
|
-
|
|
1487
|
-
目的:保证 IR 编译稳定、可 diff。
|
|
1488
|
-
|
|
1489
|
-
### 7.3 Dry-run tests
|
|
1490
|
-
|
|
1491
|
-
```bash
|
|
1492
|
-
loop-agent dag workflow-validate --workflow fixture.workflow.json
|
|
1493
|
-
loop-agent dag workflow-compile --workflow fixture.workflow.json --output /tmp/fixture.dag.json
|
|
1494
|
-
loop-agent dag validate --dag /tmp/fixture.dag.json --strict-governance
|
|
1495
|
-
```
|
|
1496
|
-
|
|
1497
|
-
### 7.4 Static executor integration tests
|
|
1498
|
-
|
|
1499
|
-
用 `static` executor 模拟:
|
|
1500
|
-
|
|
1501
|
-
- discover files output。
|
|
1502
|
-
- reviewer findings output。
|
|
1503
|
-
- verifier status output。
|
|
1504
|
-
- reducer report output。
|
|
1505
|
-
|
|
1506
|
-
不依赖外部模型,CI 稳定。
|
|
1507
|
-
|
|
1508
|
-
### 7.5 Shell-only smoke tests
|
|
1509
|
-
|
|
1510
|
-
用只读 command:
|
|
1511
|
-
|
|
1512
|
-
```bash
|
|
1513
|
-
git diff --name-only main...HEAD
|
|
1514
|
-
```
|
|
1515
|
-
|
|
1516
|
-
测试真实 command allowlist、cwd、stdout parsing、artifact。
|
|
1517
|
-
|
|
1518
|
-
### 7.6 Model executor dogfood tests
|
|
1519
|
-
|
|
1520
|
-
在本地或非 CI 环境跑:
|
|
1521
|
-
|
|
1522
|
-
- Pi reviewer。
|
|
1523
|
-
- Pi verifier。
|
|
1524
|
-
- Cursor read-only reviewer。
|
|
1525
|
-
- 小 repo / 小目录。
|
|
1526
|
-
|
|
1527
|
-
### 7.7 Loop integration tests
|
|
1528
|
-
|
|
1529
|
-
验证:
|
|
1530
|
-
|
|
1531
|
-
- workflow action append round。
|
|
1532
|
-
- workflow report ref 进入 closeout。
|
|
1533
|
-
- signal -> workflow input。
|
|
1534
|
-
- failureStreak 影响 `loop --auto`。
|
|
1535
|
-
- Loop 不改写 completed DAG facts。
|
|
1536
|
-
|
|
1537
|
-
---
|
|
1538
|
-
|
|
1539
|
-
## 8. 风险与治理策略
|
|
1540
|
-
|
|
1541
|
-
### 8.1 禁止任意代码作为 workflow IR
|
|
1542
|
-
|
|
1543
|
-
不要支持:
|
|
1544
|
-
|
|
1545
|
-
```json
|
|
1546
|
-
{ "eval": "some JavaScript" }
|
|
1547
|
-
```
|
|
1548
|
-
|
|
1549
|
-
也不要支持:
|
|
1550
|
-
|
|
1551
|
-
```json
|
|
1552
|
-
{ "shell": "{{model_generated_command}}" }
|
|
1553
|
-
```
|
|
1554
|
-
|
|
1555
|
-
表达力不够时,新增 bounded primitive:
|
|
1556
|
-
|
|
1557
|
-
```text
|
|
1558
|
-
agent
|
|
1559
|
-
map_agent
|
|
1560
|
-
verify_agent
|
|
1561
|
-
reduce_agent
|
|
1562
|
-
command
|
|
1563
|
-
condition
|
|
1564
|
-
loop_until
|
|
1565
|
-
human_gate
|
|
1566
|
-
artifact_transform
|
|
1567
|
-
subworkflow
|
|
1568
|
-
```
|
|
1569
|
-
|
|
1570
|
-
### 8.2 强制 limits
|
|
1571
|
-
|
|
1572
|
-
WorkflowSpec 必须有默认 limits,且 runtime 有硬上限:
|
|
1573
|
-
|
|
1574
|
-
```json
|
|
1575
|
-
{
|
|
1576
|
-
"maxConcurrency": 8,
|
|
1577
|
-
"maxAgentRuns": 100,
|
|
1578
|
-
"maxExpandedNodes": 200,
|
|
1579
|
-
"maxRetriesPerNode": 1,
|
|
1580
|
-
"maxIterations": 3,
|
|
1581
|
-
"maxWallClockMinutes": 30
|
|
1582
|
-
}
|
|
1583
|
-
```
|
|
1584
|
-
|
|
1585
|
-
不能相信 planner 自己节制。
|
|
1586
|
-
|
|
1587
|
-
### 8.3 权限与写入范围
|
|
1588
|
-
|
|
1589
|
-
- read-only workflow 默认风险低。
|
|
1590
|
-
- edits 必须声明 `allowedPaths` / `forbiddenPaths` / `writeSet`。
|
|
1591
|
-
- 同 rank writeSet 冲突必须 fail。
|
|
1592
|
-
- broad writeSet 必须 human_gate。
|
|
1593
|
-
- command 必须 allowlist。
|
|
1594
|
-
- network 默认 deny。
|
|
1595
|
-
- secrets 默认不可见。
|
|
1596
|
-
|
|
1597
|
-
### 8.4 Verifier 独立性
|
|
1598
|
-
|
|
1599
|
-
- producer 不能 verify 自己的 finding。
|
|
1600
|
-
- verifier 只看 finding、evidence、target artifact。
|
|
1601
|
-
- reducer 不新增 facts。
|
|
1602
|
-
- final report 默认只包含 verified findings。
|
|
1603
|
-
|
|
1604
|
-
### 8.5 Completed facts 不可改写
|
|
1605
|
-
|
|
1606
|
-
- DAG run artifact 是事实源。
|
|
1607
|
-
- Workflow report 可以 summarize,但不改写 node output。
|
|
1608
|
-
- Loop 可以引用 workflow/DAG facts,但不改写 completed DAG facts。
|
|
1609
|
-
|
|
1610
|
-
---
|
|
1611
|
-
|
|
1612
|
-
## 9. 推荐 PR 顺序
|
|
1613
|
-
|
|
1614
|
-
### PR 1:文档与对象边界
|
|
1615
|
-
|
|
1616
|
-
- 添加/更新本文档。
|
|
1617
|
-
- 必要时更新 CLI help 文案,但不要在没有实现的情况下承诺 `workflow` 顶层命令。
|
|
1618
|
-
- 明确 DAG / Workflow / Loop 分层。
|
|
1619
|
-
- 明确 Level 1 fallback 已删除,不能作为 workflow 基础。
|
|
1620
|
-
|
|
1621
|
-
### PR 2:WorkflowSpec schema + validator
|
|
1622
|
-
|
|
1623
|
-
- 新增 `src/workflows/dynamic/spec.ts`。
|
|
1624
|
-
- 新增 validator。
|
|
1625
|
-
- 加 fixture tests。
|
|
1626
|
-
- 新增 `dag workflow-validate` 实验入口。
|
|
1627
|
-
|
|
1628
|
-
### PR 3:workflow compile v0
|
|
1629
|
-
|
|
1630
|
-
- 支持 agent / command / reduce / artifact_transform。
|
|
1631
|
-
- 产出 existing AgentDAG。
|
|
1632
|
-
- 通过 existing `dag validate`。
|
|
1633
|
-
- 产出 compile manifest 或扩展后的稳定 `DagSpec` origin 字段。
|
|
1634
|
-
|
|
1635
|
-
### PR 4:map_agent dynamic expansion
|
|
1636
|
-
|
|
1637
|
-
- 支持 `itemsFrom`。
|
|
1638
|
-
- 写 expansion manifest。
|
|
1639
|
-
- 支持 resume 不重复展开。
|
|
1640
|
-
- 明确 runner expansion seam,不隐式改写 completed DAG facts。
|
|
1641
|
-
|
|
1642
|
-
### PR 5:verify_agent + Finding/Verification artifact
|
|
1643
|
-
|
|
1644
|
-
- 标准化 finding / verification。
|
|
1645
|
-
- reducer 默认只包含 verified。
|
|
1646
|
-
|
|
1647
|
-
### PR 6:pr-review profile
|
|
1648
|
-
|
|
1649
|
-
- read-only MVP。
|
|
1650
|
-
- fixture + static executor + optional model dogfood。
|
|
1651
|
-
|
|
1652
|
-
### PR 7:loop workflow action
|
|
1653
|
-
|
|
1654
|
-
- `loop run --action workflow`。
|
|
1655
|
-
- round 记录 workflowRef / runRef / reportRef。
|
|
1656
|
-
- closeout 汇总 workflow evidence。
|
|
1657
|
-
|
|
1658
|
-
### PR 8:condition / loop_until
|
|
1659
|
-
|
|
1660
|
-
- bounded loop。
|
|
1661
|
-
- fix-until-check-passes profile。
|
|
1662
|
-
|
|
1663
|
-
### PR 9:workflow save / run / replay
|
|
1664
|
-
|
|
1665
|
-
- `.loop-agent/workflows/`。
|
|
1666
|
-
- `workflow list/inspect/run/save/replay`。
|
|
1667
|
-
|
|
1668
|
-
### PR 10:operator UX
|
|
1669
|
-
|
|
1670
|
-
- 优先增强现有 status / doctor / report / decision / resume。
|
|
1671
|
-
- 只有在真实操作痛点出现后,再考虑 inspect-node / restart-node / stop。
|
|
1672
|
-
|
|
1673
|
-
---
|
|
1674
|
-
|
|
1675
|
-
## 10. 非目标
|
|
1676
|
-
|
|
1677
|
-
短期不要做:
|
|
1678
|
-
|
|
1679
|
-
- 完整 JS workflow runtime。
|
|
1680
|
-
- 任意代码 eval。
|
|
1681
|
-
- 无限制 autonomous loop。
|
|
1682
|
-
- 大规模自动改代码。
|
|
1683
|
-
- 多 writer agent 在同一 worktree 并发写。
|
|
1684
|
-
- 用 Loop 替代 DAG runner。
|
|
1685
|
-
- 用 reducer 重新审计 facts。
|
|
1686
|
-
- 用模型自述替代 shell verification。
|
|
1687
|
-
- 在 IR 未稳定前新增顶层 `workflow` 公共命令。
|
|
1688
|
-
- 为了支持 Dynamic Workflow 恢复 Level 1 顺序工作流。
|
|
1689
|
-
|
|
1690
|
-
---
|
|
1691
|
-
|
|
1692
|
-
## 11. 成功标准
|
|
1693
|
-
|
|
1694
|
-
### 技术成功标准
|
|
1695
|
-
|
|
1696
|
-
- WorkflowSpec 是稳定、可审查、可 diff 的 artifact。
|
|
1697
|
-
- Dynamic workflow 可以编译成现有 Agent DAG。
|
|
1698
|
-
- compile manifest 或 `DagSpec` origin 字段能追踪 workflow node 到 DAG task 的映射。
|
|
1699
|
-
- map_agent 可以根据上游 output 动态展开。
|
|
1700
|
-
- verify_agent 可以独立验证 findings。
|
|
1701
|
-
- reducer 可以输出 verified-first report。
|
|
1702
|
-
- Loop 可以记录 workflow run evidence。
|
|
1703
|
-
- 所有阶段都有 deterministic tests。
|
|
1704
|
-
|
|
1705
|
-
### 产品成功标准
|
|
1706
|
-
|
|
1707
|
-
用户可以这样理解系统:
|
|
1708
|
-
|
|
1709
|
-
```text
|
|
1710
|
-
普通任务:用 DAG runtime。
|
|
1711
|
-
一次复杂并行任务:用 Dynamic Workflow。
|
|
1712
|
-
长期多轮任务:用 Loop Task 管多个 workflow/DAG/shell/review round。
|
|
1713
|
-
```
|
|
1714
|
-
|
|
1715
|
-
### 治理成功标准
|
|
1716
|
-
|
|
1717
|
-
- 高风险 workflow 必须审批。
|
|
1718
|
-
- 所有 fan-out 有硬上限。
|
|
1719
|
-
- 所有 shell 命令可审计。
|
|
1720
|
-
- 所有写入范围可审计。
|
|
1721
|
-
- 所有 completed facts 有 artifact ref。
|
|
1722
|
-
- closeout 有 verification evidence。
|
|
1723
|
-
|
|
1724
|
-
---
|
|
1725
|
-
|
|
1726
|
-
## 12. 最终定位文案
|
|
1727
|
-
|
|
1728
|
-
中文:
|
|
1729
|
-
|
|
1730
|
-
> `loop-agent` 是一个 repo-local AI coding workflow runtime。它以 DAG runtime 作为执行内核,在其上通过 Dynamic Workflow DAG Engine 把复杂任务动态编译为可验证的 Agent DAG;对于长期目标,Loop Task 将多次 workflow run、DAG run、shell verification、人工反馈和 closeout 串成可恢复、可审查、可交付的工程闭环。
|
|
1731
|
-
|
|
1732
|
-
英文:
|
|
1733
|
-
|
|
1734
|
-
> `loop-agent` is a repo-local AI coding workflow runtime. Its DAG runtime executes concrete Agent DAGs with artifacts and verification. The Dynamic Workflow DAG Engine compiles high-level workflow specs into expanded, verifiable Agent DAGs. For long-running objectives, Loop Task coordinates multiple workflow, DAG, shell, and review rounds into a recoverable and auditable delivery loop.
|
|
1735
|
-
|
|
1736
|
-
---
|
|
1737
|
-
|
|
1738
|
-
## 参考来源
|
|
1739
|
-
|
|
1740
|
-
[1] Anthropic Claude Code Docs, “Orchestrate subagents at scale with dynamic workflows”, accessed 2026-07-04.
|
|
1741
|
-
https://code.claude.com/docs/en/workflows
|
|
1742
|
-
|
|
1743
|
-
[2] 用户上传文档:`粘贴的 markdown (1).md`,关于用 DAG JSON 复刻 Claude Dynamic Workflows 的设计说明。
|
|
1744
|
-
|
|
1745
|
-
[3] 用户上传文档:`2026-07-02-repository-analysis.md`,关于当前 `loop-agent` 仓库结构、DAG 主路径、Loop 语义、治理边界与健康度的分析报告。
|
|
1746
|
-
|
|
1747
|
-
[4] 当前源码仓库历史 completed execution plan,关于删除 Level 1 fallback、抽取 shell verification、建立 DAG-oriented task read model 的完成记录;发布包只携带 execution plan 目录说明,不携带具体历史计划正文。
|
|
1748
|
-
|
|
1749
|
-
[5] 当前源码复核:`src/workflows/dag/types.ts`、`src/workflows/dag/validate.ts`、`src/workflows/dag/runner.ts`、`src/workflows/loop/actions.ts`、`src/task/read-model.ts`、`src/cli/catalog.ts`。
|
|
1
|
+
# loop-agent Dynamic Workflow DAG Engine 阶段规划
|
|
2
|
+
|
|
3
|
+
版本:0.2
|
|
4
|
+
日期:2026-07-04
|
|
5
|
+
适用项目:`loop-agent`
|
|
6
|
+
目标读者:项目维护者、实现者、后续接手的 coding agent
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 0. 摘要
|
|
11
|
+
|
|
12
|
+
`loop-agent` 当前已经具备一个较成熟的 **DAG runtime**:它能把 AI coding task 固化为本地任务目录,生成/校验 Agent DAG,调度 Cursor、Pi、shell、static 等 executor,保存 artifacts、logs、decision envelope、report,并以 shell verification 作为完成证据。
|
|
13
|
+
|
|
14
|
+
2026-07-04 复核当前代码后,结论是:
|
|
15
|
+
|
|
16
|
+
> 这个架构方向适合当前项目,但只适合作为 **现有 DAG runtime 上方的逻辑编排/编译层**。
|
|
17
|
+
> 不适合重写 runner,不适合恢复已删除的 Level 1 顺序 fallback,也不适合照搬 Claude Dynamic Workflows 的 JavaScript script 形态。
|
|
18
|
+
|
|
19
|
+
当前更合适的方向是:
|
|
20
|
+
|
|
21
|
+
> 在现有 DAG runtime 上方新增一个 **Dynamic Workflow DAG Engine**。
|
|
22
|
+
> LLM 或 profile 先生成受 schema 约束的 `WorkflowSpec`;engine 对其做校验、风险分析、动态展开和编译;最终产物仍然交给现有 `run-dag` 执行。
|
|
23
|
+
|
|
24
|
+
核心分层:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
Loop Task
|
|
28
|
+
管多轮目标、round、signal、context、failureStreak、closeout
|
|
29
|
+
|
|
30
|
+
Dynamic Workflow DAG Engine
|
|
31
|
+
管一次 run 内的动态拆解、map/reduce/verify/condition/loop_until/human_gate
|
|
32
|
+
|
|
33
|
+
DAG runtime
|
|
34
|
+
管 concrete DAG 的 validate、schedule、execute、retry、resume、artifact、report
|
|
35
|
+
|
|
36
|
+
Executors
|
|
37
|
+
Cursor / Pi / shell / static
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
一句话定位:
|
|
41
|
+
|
|
42
|
+
> DAG runtime 解决“如何可靠执行具体 DAG”;Dynamic Workflow DAG Engine 解决“如何把复杂任务动态编译成具体 DAG”;Loop Task 解决“多次 workflow/DAG/shell/review round 如何形成长期目标闭环”。
|
|
43
|
+
|
|
44
|
+
### 0.1 适配性判断
|
|
45
|
+
|
|
46
|
+
| 判断 | 结论 | 原因 |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| 是否值得做 | 值得,但应分阶段 | 现有 DAG runtime 已经提供 executor、artifact、approval、report、resume 的深 Module,Dynamic Workflow 可以复用这些 leverage |
|
|
49
|
+
| 是否应改 runner 为 JS workflow runtime | 不应 | 任意脚本会削弱 schema 审计、权限分析和 repo governance |
|
|
50
|
+
| 是否应先做自动修代码 workflow | 不应 | 当前最稳的 MVP 是 read-only PR/code review,先验证 fan-out、verifier、reducer |
|
|
51
|
+
| 是否应马上接入 Loop | 不应前置 | Loop 现在已有 `dag` action;workflow action 应在 WorkflowSpec/compile/report 稳定后再接 |
|
|
52
|
+
| 最大技术风险 | runtime expansion | 当前 `run-dag` 基于静态 `DagSpec.tasks` 和 topo ranks;真正动态插入节点需要 runner 层扩展 |
|
|
53
|
+
| 第一优先级 | WorkflowSpec schema + validator + static compiler | 这能先形成可审查 artifact,并证明能编译到现有 `DagSpec` |
|
|
54
|
+
|
|
55
|
+
### 0.2 当前代码对本设计的约束
|
|
56
|
+
|
|
57
|
+
- `DagTask.id` 当前必须是 kebab-case:`/^[a-z][a-z0-9-]*$/`。WorkflowSpec 示例也应使用 kebab-case,或由 compiler 显式维护 workflow id 到 DAG id 的映射。
|
|
58
|
+
- `DagSpec` 目前没有通用 metadata 字段;未知字段不会成为稳定契约。若要保留 `workflowRef`、`workflowNodeId`、compile manifest,应新增明确 schema 字段或使用 sidecar manifest。
|
|
59
|
+
- `run-dag` 当前启动时从完整 `DagSpec.tasks` 计算 topo ranks;Phase 3 以前不应假设 child nodes 能自然“进入 existing scheduler”。
|
|
60
|
+
- DAG 已有 `decisionGate`、`dag approve`、`dag reject`、`dag resume` 和 paused lifecycle。`human_gate` 应优先编译到这套已有机制,而不是发明第二套 approval runtime。
|
|
61
|
+
- `loop` 当前支持 `shell-verify`、`pi-review`、`cursor-fix`、`dag`、`record-round`、`add-signal`、`closeout`;没有 `workflow` action。
|
|
62
|
+
- Level 1 顺序 fallback 已在 `refactor: remove level1 fallback` 后删除;本文档不得再把 `src/workflows/level1/` 描述为保留兼容路径。
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 1. 思想来源
|
|
67
|
+
|
|
68
|
+
### 1.1 Claude Dynamic Workflows 的核心启发
|
|
69
|
+
|
|
70
|
+
Claude Code Dynamic Workflows 的官方定义是:Claude 为任务写出一个 JavaScript orchestration script,runtime 在后台执行它;workflow 适用于 codebase audit、大规模 migration、cross-checked research 等超出单轮对话协调能力的任务。官方文档强调,workflow 与 subagents / skills / agent teams 的关键区别不是“能不能多 agent”,而是 **谁持有计划**:subagent 和 agent team 仍由 Claude 或 lead agent 逐轮决定下一步;workflow 由 script 决定下一步,中间状态存在 script variables 中,而不是反复塞回模型上下文。官方文档还明确提到 workflow 可以将 repeatable quality pattern 编码化,例如让独立 agents adversarially review each other’s findings,再进入最终报告。[1]
|
|
71
|
+
|
|
72
|
+
Claude 方案的关键模式:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
用户目标
|
|
76
|
+
-> workflow script / runtime 持有计划
|
|
77
|
+
-> fan-out 多个 subagents
|
|
78
|
+
-> 中间结果留在 runtime state
|
|
79
|
+
-> verifier / reducer 过滤、去重、排序
|
|
80
|
+
-> session 只接收最终结果
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
官方文档列出的典型场景包括:
|
|
84
|
+
|
|
85
|
+
- 审计许多文件中的同一类问题。
|
|
86
|
+
- 持续修复直到检查通过。
|
|
87
|
+
- 并行迁移大量文件。
|
|
88
|
+
- Review every changed file and write one summary。
|
|
89
|
+
- 跨多个来源 research 并交叉验证。
|
|
90
|
+
- Find issues until the list stops growing。[1]
|
|
91
|
+
|
|
92
|
+
### 1.2 对 loop-agent 更合适的改造:JS script -> Dynamic DAG IR
|
|
93
|
+
|
|
94
|
+
Claude 的 JS workflow 具有强表达力,但对 `loop-agent` 这种希望产品化、可审计、本地治理的 runtime 来说,JS script 不是最优 IR。更好的方向是:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
LLM / profile 生成 WorkflowSpec JSON
|
|
98
|
+
-> schema validator
|
|
99
|
+
-> risk / permission analyzer
|
|
100
|
+
-> compiler / dynamic expander
|
|
101
|
+
-> concrete Agent DAG
|
|
102
|
+
-> existing DAG runtime
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
原因:
|
|
106
|
+
|
|
107
|
+
| 维度 | Claude JS workflow | Dynamic DAG IR |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| 表达力 | 很强,天然支持 JS loop / branch / variables | 中等,需要 node type 扩展 |
|
|
110
|
+
| 安全审计 | 需要审 JS code | 可以审 schema + primitive |
|
|
111
|
+
| 权限分析 | 较难静态判断 | 容易做 limits / permissions / writeSet 检查 |
|
|
112
|
+
| 可视化 | 脚本不天然图形化 | DAG / logical workflow 天然可视化 |
|
|
113
|
+
| 恢复与重放 | 可以,但依赖 script runtime | 可以基于 run state / artifact ref / compiled DAG 做强恢复 |
|
|
114
|
+
| 产品化 | 面向 Claude Code 内部体验 | 更适合 repo-local CLI + governance |
|
|
115
|
+
|
|
116
|
+
因此,本项目不应追求“复刻 Claude 的 JS script”,而应复刻其操作系统思想:
|
|
117
|
+
|
|
118
|
+
> 编排权离开模型上下文,进入一个可读、可校验、可恢复、可复跑的 workflow artifact。
|
|
119
|
+
|
|
120
|
+
### 1.3 本项目已有思想基础
|
|
121
|
+
|
|
122
|
+
`loop-agent` 当前已经具备以下基础:
|
|
123
|
+
|
|
124
|
+
- repo-local task harness。
|
|
125
|
+
- Agent DAG 编排。
|
|
126
|
+
- DAG validation。
|
|
127
|
+
- DAG report / doctor / recovery recommendation。
|
|
128
|
+
- decision envelope、human approval/rejection、paused/resume lifecycle。
|
|
129
|
+
- supervised DAG convergence pass。
|
|
130
|
+
- Cursor / Pi / shell / static executor registry。
|
|
131
|
+
- `shell-verification` Module,供 DAG shell executor 复用。
|
|
132
|
+
- DAG-oriented task read model。
|
|
133
|
+
- `.harness/` 运行态状态与 artifacts。
|
|
134
|
+
- shell verification 作为完成权威。
|
|
135
|
+
- governance 检查。
|
|
136
|
+
- Loop 长周期 round / signal / closeout 状态机。
|
|
137
|
+
|
|
138
|
+
这些能力说明当前项目已经拥有 Dynamic Workflow 所需的执行内核和治理底座。缺少的不是“再写一个 runtime”,而是上一层的 **WorkflowSpec + workflow validator + risk analyzer + compiler + dynamic expansion + workflow report + workflow/loop integration**。
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 2. 当前代码现状判断
|
|
143
|
+
|
|
144
|
+
基于当前仓库分析,`loop-agent` 可以被描述为:
|
|
145
|
+
|
|
146
|
+
> 一个 repo-local agent workflow runtime。它为 AI coding agent 提供任务 harness、Agent DAG 编排、Cursor/Pi 执行器集成、确定性 shell 验证、运行证据归档和治理检查,让长期或复杂的 agent 实现工作可以被审查、恢复和交付。
|
|
147
|
+
|
|
148
|
+
本次复核依据的关键代码与文档:
|
|
149
|
+
|
|
150
|
+
- `docs/feature-workflow.md`
|
|
151
|
+
- 源码仓库历史 completed execution plan: remove-level1-fallback
|
|
152
|
+
- `src/workflows/dag/types.ts`
|
|
153
|
+
- `src/workflows/dag/validate.ts`
|
|
154
|
+
- `src/workflows/dag/runner.ts`
|
|
155
|
+
- `src/workflows/dag/lifecycle.ts`
|
|
156
|
+
- `src/workflows/dag/report.ts`
|
|
157
|
+
- `src/workflows/dag/init-hybrid.ts`
|
|
158
|
+
- `src/workflows/loop/actions.ts`
|
|
159
|
+
- `src/commands/loop.ts`
|
|
160
|
+
- `src/commands/dag-run-task.ts`
|
|
161
|
+
- `src/commands/dag-validate.ts`
|
|
162
|
+
- `src/task/read-model.ts`
|
|
163
|
+
- `src/cli/catalog.ts`
|
|
164
|
+
|
|
165
|
+
### 2.1 当前主路径
|
|
166
|
+
|
|
167
|
+
当前主推荐路径已经是 DAG:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
loop-agent new-task <task-id> "Task title"
|
|
171
|
+
loop-agent dag run-task <task-id> --profile auto --strict-models --output /tmp/<task-id>-dag.json
|
|
172
|
+
loop-agent dag validate --dag /tmp/<task-id>-dag.json --strict-models --strict-governance
|
|
173
|
+
loop-agent run-dag --dag /tmp/<task-id>-dag.json --cwd .
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
主路径语义:
|
|
177
|
+
|
|
178
|
+
| 命令 | 作用 |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `new-task` | 创建 `.harness/tasks/<taskId>` 和 task config/source 结构;legacy workflow state 只作为兼容读输入 |
|
|
181
|
+
| `dag run-task` | 根据任务上下文生成 DAG 草案 |
|
|
182
|
+
| `dag validate` | 校验依赖、写入策略、shell 配置、decision gate、同 rank 写冲突等 |
|
|
183
|
+
| `run-dag` | 执行 DAG,生成 `.harness/dag-runs/<lifecycle>/<runId>` 下的状态、节点 artifacts、报告材料 |
|
|
184
|
+
|
|
185
|
+
### 2.2 当前目录职责
|
|
186
|
+
|
|
187
|
+
| 路径 | 当前职责 | 对 Dynamic Workflow 的意义 |
|
|
188
|
+
|---|---|---|
|
|
189
|
+
| `src/workflows/dag/` | Agent DAG 类型、校验、执行、报告、decision envelope、recovery 建议 | 保留为 concrete DAG runtime 内核 |
|
|
190
|
+
| `src/commands/` | 顶层命令实现,当前命令文件是扁平布局 | 先新增 `dag workflow-*` 子命令实现;稳定后再考虑顶层 `workflow` |
|
|
191
|
+
| `src/task/` | `.harness/tasks/<taskId>` 的 task config、state、artifact、source hash、read model | WorkflowSpec / compiled DAG 可以落在 task 目录下,read model 后续应能暴露 workflow refs |
|
|
192
|
+
| `src/executors/` | Cursor、Pi、shell、static executor 适配 | Dynamic engine 不绕过 executor,只生成节点给 executor 执行 |
|
|
193
|
+
| `src/governance/` | skill safety、repo governance 等规则检查 | 扩展到 workflow-level risk / permission analyzer |
|
|
194
|
+
| `.harness/` | runtime state、tasks、dag-runs、runs、prompts、缓存、live state | 新增 workflow planned/compiled/report state |
|
|
195
|
+
| `src/executors/shell-verification.ts` | shell verification preset、command execution/report/env policy | Workflow command node 应复用这里的 shell 语义 |
|
|
196
|
+
| `src/task/read-model.ts` | DAG-oriented task status / next action 推导 | 后续纳入 workflow planned/compiled/run/report refs |
|
|
197
|
+
|
|
198
|
+
### 2.3 当前 Loop 语义
|
|
199
|
+
|
|
200
|
+
顶层 `loop` 已经是 DAG 之上的长周期任务状态机:
|
|
201
|
+
|
|
202
|
+
```text
|
|
203
|
+
DAG 管一轮怎么执行和验证;
|
|
204
|
+
Loop 管多轮为什么继续、下一步做什么、哪些事实已经验证、何时暂停或收口。
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Loop 当前维护:
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
.harness/tasks/<taskId>/loop/
|
|
211
|
+
objective.md
|
|
212
|
+
context.md
|
|
213
|
+
state.json
|
|
214
|
+
rounds.jsonl
|
|
215
|
+
signals.jsonl
|
|
216
|
+
events.jsonl
|
|
217
|
+
verification/
|
|
218
|
+
review/
|
|
219
|
+
closeout.md
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Loop state 中已有适合与 Dynamic Workflow 对接的字段:
|
|
223
|
+
|
|
224
|
+
| 字段 | 结合点 |
|
|
225
|
+
|---|---|
|
|
226
|
+
| `openFrontier` | 选择下一轮 workflow profile |
|
|
227
|
+
| `failureStreak` | 决定继续、暂停、升级或换 workflow |
|
|
228
|
+
| `completedCriteria` | 判断 closeout 是否可完成 |
|
|
229
|
+
| `signals.jsonl` | 将 human instruction / approval / scope change 作为 workflow inputs |
|
|
230
|
+
| `rounds.jsonl` | 记录 workflow run ref、report ref、verification summary |
|
|
231
|
+
|
|
232
|
+
### 2.4 当前项目已有优势
|
|
233
|
+
|
|
234
|
+
1. **执行内核已有**:不需要重新实现 executor pool、artifact store、shell verification。
|
|
235
|
+
2. **治理方向正确**:已经强调 shell verification 是完成权威,模型输出不能替代验证。
|
|
236
|
+
3. **DAG lifecycle 已有**:active/paused/completed run 目录、approval/rejection、resume/report 已经是现成底座。
|
|
237
|
+
4. **任务状态正在 DAG 化**:`task-read-model` 已经把 source、DAG draft、DAG run、promotion、closeout 作为主状态面。
|
|
238
|
+
5. **Loop 已能记录长期事实**:适合承接 workflow run 结果,但不应在 MVP 前置。
|
|
239
|
+
6. **测试基础较强**:已有 DAG runner、DAG validate、DAG report、decision gate、executor、task runtime、governance、loop workflow 等测试覆盖。
|
|
240
|
+
|
|
241
|
+
### 2.5 当前主要缺口
|
|
242
|
+
|
|
243
|
+
| 缺口 | 表现 | 需要新增 |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| 没有 WorkflowSpec IR | 当前 DAG 是 concrete execution graph,不表达 logical primitive | `src/workflows/dynamic/spec.ts` |
|
|
246
|
+
| 没有 workflow-level validator | 现有 validator 只理解 `DagSpec` | `src/workflows/dynamic/validate.ts` |
|
|
247
|
+
| 没有 workflow compiler | 不能从 logical workflow 编译到现有 Agent DAG | `src/workflows/dynamic/compile.ts` |
|
|
248
|
+
| 没有 workflow metadata 保留策略 | `DagSpec` 当前没有稳定 metadata 字段 | `compile manifest` sidecar 或显式扩展 `DagSpec` schema |
|
|
249
|
+
| 没有 dynamic expansion | 静态 DAG 不能自然表达 discover -> map N items;runner ranks 当前启动时固定 | `map_agent` expansion runtime + DAG runner expansion seam |
|
|
250
|
+
| verification 不是一等 workflow pattern | 可以审查,但没有 Finding/Verification 标准 artifact | `verify_agent` + artifact schema |
|
|
251
|
+
| bounded loop 未进入 workflow 层 | 当前 DAG convergence 是固定 supervised chain,不是通用 `loop_until` primitive | `loop_until` bounded expansion |
|
|
252
|
+
| workflow 与 Loop 未打通 | Loop 当前有 `dag` action,但没有 `workflow` action | `loop run --action workflow`,在 compiler/report 稳定后做 |
|
|
253
|
+
| saved workflow/replay 未产品化 | DAG 可保存和 report,但 workflow 复用层还没有 | `.loop-agent/workflows/` / `workflow run` |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## 3. 三层定位:Dynamic Workflow Engine、DAG runtime、Loop Task
|
|
258
|
+
|
|
259
|
+
### 3.1 DAG runtime
|
|
260
|
+
|
|
261
|
+
一句话:
|
|
262
|
+
|
|
263
|
+
> 给我一个 concrete DAG,我负责可靠、安全、可恢复地执行它。
|
|
264
|
+
|
|
265
|
+
职责:
|
|
266
|
+
|
|
267
|
+
- validate concrete DAG。
|
|
268
|
+
- 检查依赖、环、缺失节点、writeSet 冲突、shell config、cwd 越界。
|
|
269
|
+
- 调度 ready nodes。
|
|
270
|
+
- 控制并发、retry、timeout、resume。
|
|
271
|
+
- 调用 Cursor / Pi / shell / static executors。
|
|
272
|
+
- 记录 node artifacts、stdout/stderr、executor result、decision envelope。
|
|
273
|
+
- 生成 DAG report。
|
|
274
|
+
|
|
275
|
+
不负责:
|
|
276
|
+
|
|
277
|
+
- 决定复杂任务要拆成多少动态节点。
|
|
278
|
+
- 根据上游输出生成新的 logical work。
|
|
279
|
+
- 管理多轮目标、用户反馈、长期 lesson。
|
|
280
|
+
|
|
281
|
+
适合场景:
|
|
282
|
+
|
|
283
|
+
- 固定步骤 coding task。
|
|
284
|
+
- 已经生成好的 DAG。
|
|
285
|
+
- 小规模 feature / bug fix。
|
|
286
|
+
- shell verification / deterministic gate。
|
|
287
|
+
|
|
288
|
+
### 3.2 Dynamic Workflow DAG Engine
|
|
289
|
+
|
|
290
|
+
一句话:
|
|
291
|
+
|
|
292
|
+
> 给我一个目标、profile 或 WorkflowSpec,我负责把它动态编排、校验、展开、编译成 concrete DAG。
|
|
293
|
+
|
|
294
|
+
职责:
|
|
295
|
+
|
|
296
|
+
- 定义 `WorkflowSpec` schema。
|
|
297
|
+
- 校验 logical workflow。
|
|
298
|
+
- 做 workflow-level risk / permission analysis。
|
|
299
|
+
- 支持 `agent`、`map_agent`、`verify_agent`、`reduce_agent`、`condition`、`loop_until`、`human_gate`、`artifact_transform`。
|
|
300
|
+
- 根据上游 output 做 dynamic expansion。
|
|
301
|
+
- 将 logical workflow 编译成 runtime 可执行的 concrete DAG。
|
|
302
|
+
- 生成 workflow-level report。
|
|
303
|
+
- 支持 workflow save / inspect / replay。
|
|
304
|
+
|
|
305
|
+
不负责:
|
|
306
|
+
|
|
307
|
+
- 直接执行 shell 或写文件。
|
|
308
|
+
- 跳过现有 DAG runtime 调 executor。
|
|
309
|
+
- 管理跨多轮目标。
|
|
310
|
+
- 改写 completed DAG facts。
|
|
311
|
+
|
|
312
|
+
适合场景:
|
|
313
|
+
|
|
314
|
+
- PR changed files review。
|
|
315
|
+
- codebase-wide audit。
|
|
316
|
+
- 多文件迁移。
|
|
317
|
+
- finding -> independent verifier -> reducer。
|
|
318
|
+
- fix-until-pass 的单 run bounded loop。
|
|
319
|
+
- 多来源 research / cross-check synthesis。
|
|
320
|
+
|
|
321
|
+
### 3.3 Loop Task
|
|
322
|
+
|
|
323
|
+
一句话:
|
|
324
|
+
|
|
325
|
+
> 管一个长期目标跨多轮为什么继续、下一步做什么、哪些事实已验证、何时暂停或 closeout。
|
|
326
|
+
|
|
327
|
+
职责:
|
|
328
|
+
|
|
329
|
+
- 维护 objective、context、state、rounds、signals、closeout。
|
|
330
|
+
- 记录每轮 action / result / verification / lesson / next / decision。
|
|
331
|
+
- 接收 human feedback、approval、scope change。
|
|
332
|
+
- 根据 `openFrontier` 与 `failureStreak` 决定下一轮动作。
|
|
333
|
+
- 汇总多个 workflow/DAG/shell/review run 形成 closeout。
|
|
334
|
+
|
|
335
|
+
不负责:
|
|
336
|
+
|
|
337
|
+
- 执行 node。
|
|
338
|
+
- 展开 map_agent。
|
|
339
|
+
- 校验 workflow schema。
|
|
340
|
+
- 直接修改 DAG run artifacts。
|
|
341
|
+
|
|
342
|
+
适合场景:
|
|
343
|
+
|
|
344
|
+
- 任务跨多轮,单次 DAG 或 workflow 难以完成。
|
|
345
|
+
- 需要保留失败教训和下一步策略。
|
|
346
|
+
- 需要吸收人工反馈、审批、范围变化。
|
|
347
|
+
- 需要把多次 DAG run / workflow run / shell verification 汇总为交付证据。
|
|
348
|
+
|
|
349
|
+
### 3.4 三者关系图
|
|
350
|
+
|
|
351
|
+
```mermaid
|
|
352
|
+
flowchart TD
|
|
353
|
+
U[User Task / Objective] --> T[Task Harness]
|
|
354
|
+
T --> L[Loop Task]
|
|
355
|
+
L -->|chooses bounded action| W[Dynamic Workflow DAG Engine]
|
|
356
|
+
W -->|WorkflowSpec validate / risk / compile / expand| D[Concrete Agent DAG]
|
|
357
|
+
D --> R[DAG runtime]
|
|
358
|
+
R --> E[Cursor / Pi / shell / static executors]
|
|
359
|
+
E --> A[Artifacts / logs / verification / reports]
|
|
360
|
+
A --> R
|
|
361
|
+
R -->|dagRunRef / reportRef| L
|
|
362
|
+
L --> C[Loop closeout]
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## 4. 目标架构
|
|
368
|
+
|
|
369
|
+
### 4.1 新增模块建议
|
|
370
|
+
|
|
371
|
+
```text
|
|
372
|
+
src/workflows/dynamic/
|
|
373
|
+
spec.ts # WorkflowSpec 类型定义
|
|
374
|
+
schema.ts # JSON schema / zod schema
|
|
375
|
+
validate.ts # logical workflow validator
|
|
376
|
+
risk.ts # workflow-level risk / permission analyzer
|
|
377
|
+
compile.ts # WorkflowSpec -> AgentDAG compiler
|
|
378
|
+
expandMap.ts # map_agent dynamic expansion
|
|
379
|
+
expandLoop.ts # loop_until bounded expansion
|
|
380
|
+
artifactRefs.ts # workflow artifact reference helpers
|
|
381
|
+
artifacts.ts # Finding / Verification / WorkflowReport types
|
|
382
|
+
profiles/
|
|
383
|
+
prReview.ts
|
|
384
|
+
auditAuth.ts
|
|
385
|
+
fixUntilCheckPasses.ts
|
|
386
|
+
report.ts # workflow-level report
|
|
387
|
+
fixtures/
|
|
388
|
+
pr-review.workflow.json
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
命令层:
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
src/commands/dag-workflow-plan.ts
|
|
395
|
+
src/commands/dag-workflow-validate.ts
|
|
396
|
+
src/commands/dag-workflow-compile.ts
|
|
397
|
+
src/commands/dag-workflow-run.ts # 可选,内部组合 validate + compile + run-dag
|
|
398
|
+
src/commands/workflow-*.ts # 稳定后再提升为顶层 workflow 命令
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Loop 对接:
|
|
402
|
+
|
|
403
|
+
```text
|
|
404
|
+
src/workflows/loop/actions.ts # 先沿用当前 Loop action 聚合文件
|
|
405
|
+
src/commands/loop.ts # 增加 --action workflow 分派
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### 4.2 运行态目录建议
|
|
409
|
+
|
|
410
|
+
```text
|
|
411
|
+
.harness/tasks/<taskId>/
|
|
412
|
+
task.json
|
|
413
|
+
|
|
414
|
+
workflows/
|
|
415
|
+
planned/
|
|
416
|
+
pr-review.workflow.json
|
|
417
|
+
validation/
|
|
418
|
+
pr-review.validation.json
|
|
419
|
+
pr-review.risk.json
|
|
420
|
+
compiled/
|
|
421
|
+
pr-review.dag.json
|
|
422
|
+
pr-review.compile-manifest.json
|
|
423
|
+
reports/
|
|
424
|
+
pr-review.workflow-report.md
|
|
425
|
+
|
|
426
|
+
loop/
|
|
427
|
+
objective.md
|
|
428
|
+
context.md
|
|
429
|
+
state.json
|
|
430
|
+
rounds.jsonl
|
|
431
|
+
signals.jsonl
|
|
432
|
+
closeout.md
|
|
433
|
+
|
|
434
|
+
.harness/dag-runs/<lifecycle>/<runId>/
|
|
435
|
+
run.json
|
|
436
|
+
state.json
|
|
437
|
+
<node-id>.json
|
|
438
|
+
<node-id>/
|
|
439
|
+
expansions/
|
|
440
|
+
review-each-file.expansion.json
|
|
441
|
+
verify-findings.expansion.json
|
|
442
|
+
# DAG report is derived by `dag report` from run facts.
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
说明:
|
|
446
|
+
|
|
447
|
+
- `.harness/tasks/<taskId>/workflows/` 保存 workflow 的计划、校验、风险、编译和 workflow-level report,是 task-local artifact。
|
|
448
|
+
- `.harness/dag-runs/<lifecycle>/<runId>/` 仍然保存 concrete DAG run facts,是执行事实源。
|
|
449
|
+
- compiled DAG 应通过 sidecar `compile-manifest.json` 或明确扩展后的 `DagSpec` 字段保留 workflow 来源。不能依赖未知 JSON 字段隐式穿过 `parseDagSpec`。
|
|
450
|
+
- Phase 3 之前,`expansions/` 只是设计目标;当前 runner 不会自动创建这个目录。
|
|
451
|
+
|
|
452
|
+
### 4.3 WorkflowSpec v0.1 草案
|
|
453
|
+
|
|
454
|
+
```json
|
|
455
|
+
{
|
|
456
|
+
"version": "0.1",
|
|
457
|
+
"kind": "dynamic-agent-workflow",
|
|
458
|
+
"meta": {
|
|
459
|
+
"name": "pr-review",
|
|
460
|
+
"description": "Review changed files and produce a ranked summary",
|
|
461
|
+
"riskLevel": "low"
|
|
462
|
+
},
|
|
463
|
+
"inputs": {
|
|
464
|
+
"base": "main",
|
|
465
|
+
"head": "HEAD"
|
|
466
|
+
},
|
|
467
|
+
"limits": {
|
|
468
|
+
"maxConcurrency": 8,
|
|
469
|
+
"maxAgentRuns": 100,
|
|
470
|
+
"maxExpandedNodes": 200,
|
|
471
|
+
"maxRetriesPerNode": 1,
|
|
472
|
+
"maxIterations": 3,
|
|
473
|
+
"maxWallClockMinutes": 30
|
|
474
|
+
},
|
|
475
|
+
"permissions": {
|
|
476
|
+
"filesystem": "read_only",
|
|
477
|
+
"shell": {
|
|
478
|
+
"mode": "allowlist",
|
|
479
|
+
"commands": ["git diff --name-only"]
|
|
480
|
+
},
|
|
481
|
+
"network": "deny",
|
|
482
|
+
"edits": "deny"
|
|
483
|
+
},
|
|
484
|
+
"nodes": [
|
|
485
|
+
{
|
|
486
|
+
"id": "discover-changed-files",
|
|
487
|
+
"type": "command",
|
|
488
|
+
"dependsOn": [],
|
|
489
|
+
"command": "git diff --name-only {{inputs.base}}...{{inputs.head}}",
|
|
490
|
+
"outputSchema": {
|
|
491
|
+
"type": "object",
|
|
492
|
+
"required": ["files"],
|
|
493
|
+
"properties": {
|
|
494
|
+
"files": {
|
|
495
|
+
"type": "array",
|
|
496
|
+
"items": { "type": "string" }
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
"id": "review-each-file",
|
|
503
|
+
"type": "map_agent",
|
|
504
|
+
"dependsOn": ["discover-changed-files"],
|
|
505
|
+
"itemsFrom": "$.nodes['discover-changed-files'].output.files",
|
|
506
|
+
"itemName": "file",
|
|
507
|
+
"concurrency": 8,
|
|
508
|
+
"role": "code-reviewer",
|
|
509
|
+
"prompt": "Review {{file}} for correctness issues. Return concrete findings only.",
|
|
510
|
+
"outputSchema": {
|
|
511
|
+
"type": "object",
|
|
512
|
+
"required": ["file", "findings"],
|
|
513
|
+
"properties": {
|
|
514
|
+
"file": { "type": "string" },
|
|
515
|
+
"findings": { "type": "array" }
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
"id": "verify-findings",
|
|
521
|
+
"type": "verify_agent",
|
|
522
|
+
"dependsOn": ["review-each-file"],
|
|
523
|
+
"itemsFrom": "$.nodes['review-each-file'].output[*].findings[*]",
|
|
524
|
+
"role": "adversarial-verifier",
|
|
525
|
+
"prompt": "Independently verify this finding. Try to refute it. Return verified, refuted, or uncertain.",
|
|
526
|
+
"outputSchema": {
|
|
527
|
+
"type": "object",
|
|
528
|
+
"required": ["findingId", "status", "reason"],
|
|
529
|
+
"properties": {
|
|
530
|
+
"findingId": { "type": "string" },
|
|
531
|
+
"status": { "type": "string", "enum": ["verified", "refuted", "uncertain"] },
|
|
532
|
+
"reason": { "type": "string" }
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
"id": "final-report",
|
|
538
|
+
"type": "reduce_agent",
|
|
539
|
+
"dependsOn": ["verify-findings"],
|
|
540
|
+
"role": "report-writer",
|
|
541
|
+
"prompt": "Create a ranked, deduplicated report. Include verified findings by default; put uncertain findings separately.",
|
|
542
|
+
"outputSchema": {
|
|
543
|
+
"type": "object",
|
|
544
|
+
"required": ["summary", "findings"],
|
|
545
|
+
"properties": {
|
|
546
|
+
"summary": { "type": "string" },
|
|
547
|
+
"findings": { "type": "array" }
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
],
|
|
552
|
+
"final": {
|
|
553
|
+
"from": "final-report"
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
命名约束:
|
|
559
|
+
|
|
560
|
+
- Workflow node id 推荐直接使用 kebab-case,并满足现有 `DagTask.id` 约束。
|
|
561
|
+
- 如果后续允许 workflow node id 比 DAG node id 更宽,compiler 必须产出显式 id mapping,并在 expansion manifest、report、Loop round 中使用同一映射。
|
|
562
|
+
- JSONPath/selector 对 kebab-case id 使用 bracket notation,例如 `$.nodes['review-each-file']...`。
|
|
563
|
+
|
|
564
|
+
### 4.4 核心约束
|
|
565
|
+
|
|
566
|
+
Validator 必须强制:
|
|
567
|
+
|
|
568
|
+
- 每个 workflow 必须有 `version`、`kind`、`nodes`、`final`。
|
|
569
|
+
- 每个 agent-like node 必须有 `outputSchema`。
|
|
570
|
+
- `map_agent` / `verify_agent` 必须有 `itemsFrom`。
|
|
571
|
+
- `command` 必须在 allowlist 内。
|
|
572
|
+
- `loop_until` 必须有 `maxIterations`。
|
|
573
|
+
- 所有 node id 唯一。
|
|
574
|
+
- 所有 dependsOn 指向存在节点。
|
|
575
|
+
- 禁止环,除非通过 `loop_until` 这种 bounded primitive 表达。
|
|
576
|
+
- 禁止 `eval` / arbitrary JS / arbitrary shell。
|
|
577
|
+
- 高风险权限必须要求 `human_gate`。
|
|
578
|
+
- producer 不能 verify 自己的 finding。
|
|
579
|
+
- reducer 默认不能新增 facts,只能 dedupe / rank / group / format。
|
|
580
|
+
- limits 必须存在默认值与硬上限。
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
## 5. 分阶段落地计划
|
|
585
|
+
|
|
586
|
+
下面的阶段按“每一步都能独立验证”的原则设计。不要一次性实现完整 engine。
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
## Phase 0:边界与命名收敛
|
|
591
|
+
|
|
592
|
+
### 目标
|
|
593
|
+
|
|
594
|
+
先把概念边界固化,避免后续代码把 `DAG`、`Workflow`、`Loop` 混在一起。
|
|
595
|
+
|
|
596
|
+
### 产物
|
|
597
|
+
|
|
598
|
+
- 将本文档作为 v0.2 roadmap 落到 `docs/`。
|
|
599
|
+
- 新增或更新对象关系图文档:`Task -> WorkflowSpec -> Compiled DAG -> DAG Run -> Loop Round -> Closeout`。
|
|
600
|
+
- CLI help 中明确:
|
|
601
|
+
- `dag` 是 concrete DAG 主路径。
|
|
602
|
+
- `dag workflow-*` 是 logical dynamic workflow 的实验入口。
|
|
603
|
+
- `loop` 是多轮长期控制层。
|
|
604
|
+
- 明确 Level 1 fallback 已删除,不作为 Dynamic Workflow 的实现基础。
|
|
605
|
+
|
|
606
|
+
### 不做
|
|
607
|
+
|
|
608
|
+
- 不改 executor。
|
|
609
|
+
- 不改 DAG runner。
|
|
610
|
+
- 不新增动态展开。
|
|
611
|
+
|
|
612
|
+
### 验证方式
|
|
613
|
+
|
|
614
|
+
```bash
|
|
615
|
+
bash scripts/check-repo.sh
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
### 退出标准
|
|
619
|
+
|
|
620
|
+
- 文档能让新实现者清楚说明三层边界。
|
|
621
|
+
- 没有新增行为风险。
|
|
622
|
+
- 不再把 Loop、Workflow、DAG runner 描述成同一层东西。
|
|
623
|
+
- 不再把 `src/workflows/level1/` 描述成当前可用路径。
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
## Phase 1:WorkflowSpec schema 与 validator
|
|
628
|
+
|
|
629
|
+
### 目标
|
|
630
|
+
|
|
631
|
+
新增 logical workflow 的类型系统和校验器,但不执行。
|
|
632
|
+
|
|
633
|
+
### 新增代码
|
|
634
|
+
|
|
635
|
+
```text
|
|
636
|
+
src/workflows/dynamic/spec.ts
|
|
637
|
+
src/workflows/dynamic/schema.ts
|
|
638
|
+
src/workflows/dynamic/validate.ts
|
|
639
|
+
src/workflows/dynamic/errors.ts
|
|
640
|
+
src/workflows/dynamic/fixtures/*.workflow.json
|
|
641
|
+
src/commands/dag-workflow-validate.ts
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### 支持 node types,仅做 schema
|
|
645
|
+
|
|
646
|
+
```text
|
|
647
|
+
agent
|
|
648
|
+
map_agent
|
|
649
|
+
verify_agent
|
|
650
|
+
reduce_agent
|
|
651
|
+
command
|
|
652
|
+
condition
|
|
653
|
+
loop_until
|
|
654
|
+
human_gate
|
|
655
|
+
artifact_transform
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
这些是 WorkflowSpec logical primitive,不等同于现有 `DagTask.executor`。Phase 1 只校验 logical Interface,不把它们直接塞进 `DagSpec.tasks`。
|
|
659
|
+
|
|
660
|
+
Phase 1 不要求全部能执行,只要求能被识别、校验、报错。
|
|
661
|
+
|
|
662
|
+
### CLI
|
|
663
|
+
|
|
664
|
+
```bash
|
|
665
|
+
loop-agent dag workflow-validate \
|
|
666
|
+
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
667
|
+
--strict-governance
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
命令应挂在现有 `dag` 子命令下;不要先新增顶层 `workflow`,避免在 IR 未稳定时扩大公共 Interface。
|
|
671
|
+
|
|
672
|
+
### Validator 规则
|
|
673
|
+
|
|
674
|
+
最低必做:
|
|
675
|
+
|
|
676
|
+
- invalid JSON fail。
|
|
677
|
+
- missing `kind` fail。
|
|
678
|
+
- missing `final` fail。
|
|
679
|
+
- duplicate node id fail。
|
|
680
|
+
- missing dependency fail。
|
|
681
|
+
- unbounded `loop_until` fail。
|
|
682
|
+
- `map_agent` without `itemsFrom` fail。
|
|
683
|
+
- `command` without allowlist fail。
|
|
684
|
+
- agent-like node without `outputSchema` fail。
|
|
685
|
+
- unknown node type fail。
|
|
686
|
+
- unknown permission mode fail。
|
|
687
|
+
- node id 非 kebab-case fail,除非 compiler 已支持显式 id mapping。
|
|
688
|
+
- `itemsFrom` selector 必须只引用已存在上游节点。
|
|
689
|
+
- `permissions.edits != deny` 时必须有 `allowedPaths` / `forbiddenPaths` / `writeSet`。
|
|
690
|
+
- broad write permissions 必须要求 `human_gate` 或编译成现有 DAG decision gate。
|
|
691
|
+
|
|
692
|
+
### 测试
|
|
693
|
+
|
|
694
|
+
```text
|
|
695
|
+
test/dynamic-workflow-validate.test.ts
|
|
696
|
+
valid-pr-review.workflow.json passes
|
|
697
|
+
missing-final.workflow.json fails
|
|
698
|
+
duplicate-node-id.workflow.json fails
|
|
699
|
+
map-without-itemsFrom.workflow.json fails
|
|
700
|
+
command-without-allowlist.workflow.json fails
|
|
701
|
+
loop-without-maxIterations.workflow.json fails
|
|
702
|
+
agent-without-outputSchema.workflow.json fails
|
|
703
|
+
non-kebab-node-id.workflow.json fails
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
### 退出标准
|
|
707
|
+
|
|
708
|
+
- 可以把一个 `WorkflowSpec` 当成可审查 artifact。
|
|
709
|
+
- 错误信息能指出具体 node id 和路径。
|
|
710
|
+
- 不接触 DAG runner,不引入执行风险。
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## Phase 2:WorkflowSpec -> AgentDAG compiler v0
|
|
715
|
+
|
|
716
|
+
### 目标
|
|
717
|
+
|
|
718
|
+
证明 logical workflow 可以稳定编译到现有 concrete Agent DAG。
|
|
719
|
+
|
|
720
|
+
### 范围
|
|
721
|
+
|
|
722
|
+
Phase 2 先支持静态可编译 node:
|
|
723
|
+
|
|
724
|
+
```text
|
|
725
|
+
agent
|
|
726
|
+
reduce_agent
|
|
727
|
+
command
|
|
728
|
+
artifact_transform
|
|
729
|
+
human_gate placeholder
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
`map_agent` / `verify_agent` 在 Phase 2 可以先编译成 placeholder/barrier node,或者只支持显式 `items` 的静态展开:
|
|
733
|
+
|
|
734
|
+
```json
|
|
735
|
+
{
|
|
736
|
+
"type": "map_agent",
|
|
737
|
+
"items": ["a.ts", "b.ts"]
|
|
738
|
+
}
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
动态 `itemsFrom` 留到 Phase 3。
|
|
742
|
+
|
|
743
|
+
### 新增代码
|
|
744
|
+
|
|
745
|
+
```text
|
|
746
|
+
src/workflows/dynamic/compile.ts
|
|
747
|
+
src/workflows/dynamic/compileTypes.ts
|
|
748
|
+
src/workflows/dynamic/artifactRefs.ts
|
|
749
|
+
src/commands/dag-workflow-compile.ts
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
### CLI
|
|
753
|
+
|
|
754
|
+
```bash
|
|
755
|
+
loop-agent dag workflow-compile \
|
|
756
|
+
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
757
|
+
--output .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
### 编译规则
|
|
761
|
+
|
|
762
|
+
- 保留 workflow node -> concrete DAG task 映射。
|
|
763
|
+
- 如果 `DagSpec` schema 暂不扩展 origin/metadata 字段,必须写 `compile-manifest.json` sidecar;不要依赖未知字段穿过 `parseDagSpec`。
|
|
764
|
+
- 每个 node 的 `outputSchema` 先转成 `outputContract` 文本或 compile manifest 约束;runtime schema enforcement 可后置。
|
|
765
|
+
- `permissions` 转成 `writePolicy`、`allowedPaths`、`forbiddenPaths`、`writeSet`、shell config 等现有 executor constraints。
|
|
766
|
+
- `limits` 转成 DAG run options、workflow validator hard cap 或 compile manifest;不要假设现有 `DagSpec` 已有全部 limit 字段。
|
|
767
|
+
- `command` 编译成 `executor: "shell"`,并复用现有 `shell` config / allowlist / timeout / cwd 约束。
|
|
768
|
+
- `agent` / `reduce_agent` 编译成 `pi` 或 `static` 节点;read-only profile 先默认 `pi`。
|
|
769
|
+
- `human_gate` 优先编译成现有 DAG `decisionGate` / paused lifecycle;不要新增第二套 approval runtime。
|
|
770
|
+
- `artifact_transform` 在 Phase 2 只允许 deterministic transform;不能引入 stub executor 作为完成实现。
|
|
771
|
+
|
|
772
|
+
### 测试
|
|
773
|
+
|
|
774
|
+
```text
|
|
775
|
+
test/dynamic-workflow-compile.test.ts
|
|
776
|
+
simple workflow compiles to existing AgentDAG shape
|
|
777
|
+
command node preserves allowlist metadata
|
|
778
|
+
reduce node depends on all upstream nodes
|
|
779
|
+
human_gate compiles to existing DAG decision gate semantics
|
|
780
|
+
workflow metadata is preserved in compile manifest or explicit DagSpec field
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
Golden fixture:
|
|
784
|
+
|
|
785
|
+
```text
|
|
786
|
+
test/fixtures/dynamic/simple.workflow.json
|
|
787
|
+
测试输出:test/fixtures/dynamic/simple.compiled-dag.json
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
### 验证命令
|
|
791
|
+
|
|
792
|
+
```bash
|
|
793
|
+
loop-agent dag workflow-validate --workflow test/fixtures/dynamic/simple.workflow.json
|
|
794
|
+
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/simple.workflow.json --output /tmp/simple.dag.json
|
|
795
|
+
loop-agent dag validate --dag /tmp/simple.dag.json --strict-governance
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
### 退出标准
|
|
799
|
+
|
|
800
|
+
- WorkflowSpec 能编译成现有 DAG validator 接受的 DAG。
|
|
801
|
+
- 现有 `run-dag` 不需要大改。
|
|
802
|
+
- 编译产物可 diff、可审查。
|
|
803
|
+
- 编译产物不包含未知 `DagSpec` 字段,或相关字段已经加入 `DagSpec` schema 和 tests。
|
|
804
|
+
|
|
805
|
+
---
|
|
806
|
+
|
|
807
|
+
## Phase 3:Dynamic expansion v0:map_agent
|
|
808
|
+
|
|
809
|
+
### 目标
|
|
810
|
+
|
|
811
|
+
实现真正的 dynamic workflow 核心:
|
|
812
|
+
|
|
813
|
+
```text
|
|
814
|
+
discover targets
|
|
815
|
+
-> map_agent dynamically expands N concrete nodes
|
|
816
|
+
-> reduce_agent fan-in
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
### 设计选择
|
|
820
|
+
|
|
821
|
+
推荐采用 **runtime expansion manifest**,而不是把所有动态能力塞进 planner。
|
|
822
|
+
|
|
823
|
+
当前 `run-dag` 在运行开始时根据 `DagSpec.tasks` 计算固定 ranks。真正的 dynamic expansion 需要新增一个明确的 runner seam,不能只在 compiler 中生成占位节点后假设 scheduler 会自动接收 child nodes。
|
|
824
|
+
|
|
825
|
+
执行到 `map_agent` 时:
|
|
826
|
+
|
|
827
|
+
1. 读取 `itemsFrom` 指向的上游 JSON output。
|
|
828
|
+
2. 校验 items 是 array。
|
|
829
|
+
3. 检查 `maxItems`、`maxExpandedNodes`、`maxAgentRuns`。
|
|
830
|
+
4. 生成 concrete child nodes:
|
|
831
|
+
|
|
832
|
+
```text
|
|
833
|
+
review-each-file-0001
|
|
834
|
+
review-each-file-0002
|
|
835
|
+
review-each-file-0003
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
5. 写入:
|
|
839
|
+
|
|
840
|
+
```text
|
|
841
|
+
.harness/dag-runs/<lifecycle>/<runId>/expansions/review-each-file.expansion.json
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
6. runner 更新 state/ranks 或通过 expansion-aware checkpoint 调度 child nodes。
|
|
845
|
+
7. `map_agent` barrier 在所有 child completed 后 completed。
|
|
846
|
+
|
|
847
|
+
### 新增代码
|
|
848
|
+
|
|
849
|
+
```text
|
|
850
|
+
src/workflows/dynamic/expandMap.ts
|
|
851
|
+
src/workflows/dag/runtimeExpansion.ts # 如果需要在 DAG runner 层接入
|
|
852
|
+
src/workflows/dag/expansionManifest.ts
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
### Expansion manifest 草案
|
|
856
|
+
|
|
857
|
+
```json
|
|
858
|
+
{
|
|
859
|
+
"workflowNodeId": "review-each-file",
|
|
860
|
+
"expandedAt": "2026-07-04T00:00:00.000Z",
|
|
861
|
+
"itemsFrom": "$.nodes['discover-changed-files'].output.files",
|
|
862
|
+
"itemCount": 3,
|
|
863
|
+
"children": [
|
|
864
|
+
{
|
|
865
|
+
"nodeId": "review-each-file-0001",
|
|
866
|
+
"itemRef": "$.items[0]",
|
|
867
|
+
"itemValueHash": "sha256:..."
|
|
868
|
+
}
|
|
869
|
+
]
|
|
870
|
+
}
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
### CLI 验证场景
|
|
874
|
+
|
|
875
|
+
先用 static executor 或 command fixture:
|
|
876
|
+
|
|
877
|
+
```text
|
|
878
|
+
discover-files static output: { "files": ["a.ts", "b.ts"] }
|
|
879
|
+
map_agent review-each-file over files
|
|
880
|
+
reduce_agent final-report
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
命令:
|
|
884
|
+
|
|
885
|
+
```bash
|
|
886
|
+
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/map.workflow.json --output /tmp/map.dag.json
|
|
887
|
+
loop-agent run-dag --dag /tmp/map.dag.json --cwd .
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
### 测试
|
|
891
|
+
|
|
892
|
+
```text
|
|
893
|
+
test/dynamic-workflow-expand-map.test.ts
|
|
894
|
+
expands N children from upstream JSON output
|
|
895
|
+
fails when itemsFrom path missing
|
|
896
|
+
fails when itemsFrom is not array
|
|
897
|
+
respects maxItems
|
|
898
|
+
respects maxExpandedNodes
|
|
899
|
+
writes expansion manifest
|
|
900
|
+
expanded child ids are valid DagTask ids
|
|
901
|
+
resume does not duplicate already-expanded children
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
### 退出标准
|
|
905
|
+
|
|
906
|
+
- 可以跑通 discover -> map -> reduce。
|
|
907
|
+
- resume 不重复生成 child nodes。
|
|
908
|
+
- expansion manifest 可审查。
|
|
909
|
+
- map fan-out 被 limits 约束。
|
|
910
|
+
|
|
911
|
+
---
|
|
912
|
+
|
|
913
|
+
## Phase 4:Finding / Verification / Reducer 标准 artifact
|
|
914
|
+
|
|
915
|
+
### 目标
|
|
916
|
+
|
|
917
|
+
把 Claude Dynamic Workflows 中最有价值的质量模式一等化:
|
|
918
|
+
|
|
919
|
+
```text
|
|
920
|
+
producer -> finding
|
|
921
|
+
finding -> independent verifier
|
|
922
|
+
verified finding -> reducer
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
### 新增标准 artifact
|
|
926
|
+
|
|
927
|
+
```ts
|
|
928
|
+
type Finding = {
|
|
929
|
+
id: string
|
|
930
|
+
sourceNodeId: string
|
|
931
|
+
targetRef: string
|
|
932
|
+
title: string
|
|
933
|
+
severity: 'low' | 'medium' | 'high' | 'critical'
|
|
934
|
+
evidence: EvidenceRef[]
|
|
935
|
+
recommendation: string
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
type Verification = {
|
|
939
|
+
findingId: string
|
|
940
|
+
verifierNodeId: string
|
|
941
|
+
status: 'verified' | 'refuted' | 'uncertain'
|
|
942
|
+
reason: string
|
|
943
|
+
evidence: EvidenceRef[]
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
type WorkflowReport = {
|
|
947
|
+
summary: string
|
|
948
|
+
verifiedFindings: Finding[]
|
|
949
|
+
uncertainFindings: Finding[]
|
|
950
|
+
refutedFindingsRef?: ArtifactRef
|
|
951
|
+
evidenceRefs: ArtifactRef[]
|
|
952
|
+
}
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
### 新增 node semantics
|
|
956
|
+
|
|
957
|
+
```text
|
|
958
|
+
verify_agent:
|
|
959
|
+
- 本质是受约束的 map_agent
|
|
960
|
+
- itemsFrom 通常指向 findings
|
|
961
|
+
- verifier 不能是 producer node
|
|
962
|
+
- verifier prompt 只能看到 finding + evidence + target artifact
|
|
963
|
+
- verifier 不看 producer chain-of-thought
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
```text
|
|
967
|
+
reduce_agent:
|
|
968
|
+
- 只做 dedupe / rank / group / format
|
|
969
|
+
- 默认不能新增事实发现
|
|
970
|
+
- final report 默认只包含 verified findings
|
|
971
|
+
- uncertain findings 单列
|
|
972
|
+
- refuted findings 只进入 appendix / trace
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
### 内置 profile:`pr-review`
|
|
976
|
+
|
|
977
|
+
第一条真实可演示 workflow:
|
|
978
|
+
|
|
979
|
+
```text
|
|
980
|
+
discover-changed-files
|
|
981
|
+
-> map_agent(review-each-file)
|
|
982
|
+
-> verify_agent(verify-each-finding)
|
|
983
|
+
-> reduce_agent(final-ranked-summary)
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
CLI:
|
|
987
|
+
|
|
988
|
+
```bash
|
|
989
|
+
loop-agent dag workflow-plan <taskId> --profile pr-review \
|
|
990
|
+
--output .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json
|
|
991
|
+
|
|
992
|
+
loop-agent dag workflow-validate \
|
|
993
|
+
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
994
|
+
--strict-governance
|
|
995
|
+
|
|
996
|
+
loop-agent dag workflow-compile \
|
|
997
|
+
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
998
|
+
--output .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json
|
|
999
|
+
|
|
1000
|
+
loop-agent run-dag \
|
|
1001
|
+
--dag .harness/tasks/<taskId>/workflows/compiled/pr-review.dag.json \
|
|
1002
|
+
--cwd .
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
### 测试
|
|
1006
|
+
|
|
1007
|
+
```text
|
|
1008
|
+
test/dynamic-workflow-verification.test.ts
|
|
1009
|
+
verify_agent expands per finding
|
|
1010
|
+
producer cannot verify own finding
|
|
1011
|
+
verified/refuted/uncertain statuses are preserved
|
|
1012
|
+
reducer includes only verified findings by default
|
|
1013
|
+
uncertain findings are separated
|
|
1014
|
+
refuted findings are excluded from main report
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
### 退出标准
|
|
1018
|
+
|
|
1019
|
+
- `pr-review` profile 能在 fixture repo 或 static executor 下跑通。
|
|
1020
|
+
- final report 能体现 verified / uncertain / refuted 分层。
|
|
1021
|
+
- reducer 不新增未验证 fact。
|
|
1022
|
+
|
|
1023
|
+
---
|
|
1024
|
+
|
|
1025
|
+
## Phase 5:Dynamic Workflow 与 Loop Task 打通
|
|
1026
|
+
|
|
1027
|
+
### 目标
|
|
1028
|
+
|
|
1029
|
+
让 Dynamic Workflow 成为 Loop 的一种 bounded action。
|
|
1030
|
+
|
|
1031
|
+
当前 Loop 已有:
|
|
1032
|
+
|
|
1033
|
+
```text
|
|
1034
|
+
loop run --action shell-verify
|
|
1035
|
+
loop run --action pi-review
|
|
1036
|
+
loop run --action cursor-fix
|
|
1037
|
+
loop run --action dag [--execute]
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
新增:
|
|
1041
|
+
|
|
1042
|
+
```bash
|
|
1043
|
+
loop-agent loop run <taskId> --action workflow --profile pr-review --execute
|
|
1044
|
+
```
|
|
1045
|
+
|
|
1046
|
+
或:
|
|
1047
|
+
|
|
1048
|
+
```bash
|
|
1049
|
+
loop-agent loop run <taskId> \
|
|
1050
|
+
--action workflow \
|
|
1051
|
+
--workflow .harness/tasks/<taskId>/workflows/planned/pr-review.workflow.json \
|
|
1052
|
+
--execute
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
### Loop round 记录格式
|
|
1056
|
+
|
|
1057
|
+
```json
|
|
1058
|
+
{
|
|
1059
|
+
"round": 4,
|
|
1060
|
+
"action": "workflow",
|
|
1061
|
+
"workflow": "pr-review",
|
|
1062
|
+
"workflowRef": ".harness/tasks/T/workflows/planned/pr-review.workflow.json",
|
|
1063
|
+
"compiledDagRef": ".harness/tasks/T/workflows/compiled/pr-review.dag.json",
|
|
1064
|
+
"compileManifestRef": ".harness/tasks/T/workflows/compiled/pr-review.compile-manifest.json",
|
|
1065
|
+
"runRef": ".harness/dag-runs/<lifecycle>/run-123",
|
|
1066
|
+
"reportRef": ".harness/tasks/T/workflows/reports/pr-review.workflow-report.md",
|
|
1067
|
+
"result": "Reviewed 17 changed files; produced 8 findings.",
|
|
1068
|
+
"verification": "5 verified, 2 refuted, 1 uncertain.",
|
|
1069
|
+
"lesson": "Most issues are concentrated in CLI routing.",
|
|
1070
|
+
"next": "Fix verified high severity findings.",
|
|
1071
|
+
"decision": "continue"
|
|
1072
|
+
}
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
### Loop context 更新原则
|
|
1076
|
+
|
|
1077
|
+
Loop `context.md` 只吸收高层事实,不复制全部 node outputs:
|
|
1078
|
+
|
|
1079
|
+
```text
|
|
1080
|
+
已验证事实:
|
|
1081
|
+
- pr-review workflow scanned 17 files.
|
|
1082
|
+
- 5 findings verified.
|
|
1083
|
+
- 1 finding uncertain.
|
|
1084
|
+
- no code edits were made.
|
|
1085
|
+
|
|
1086
|
+
下一步:
|
|
1087
|
+
- run fix-verified-findings workflow after human approval.
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
### signals -> workflow inputs
|
|
1091
|
+
|
|
1092
|
+
`signals.jsonl` 中的人工反馈应成为 workflow inputs:
|
|
1093
|
+
|
|
1094
|
+
```json
|
|
1095
|
+
{
|
|
1096
|
+
"severityFilter": ["high", "critical"],
|
|
1097
|
+
"forbiddenPaths": ["billing/**"],
|
|
1098
|
+
"humanInstructionsRef": ".harness/tasks/T/loop/signals.jsonl"
|
|
1099
|
+
}
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1102
|
+
### 测试
|
|
1103
|
+
|
|
1104
|
+
```text
|
|
1105
|
+
test/loop-workflow-action.test.ts
|
|
1106
|
+
loop workflow action records workflowRef/runRef/reportRef
|
|
1107
|
+
loop context updates from workflow summary
|
|
1108
|
+
loop does not rewrite DAG run artifacts
|
|
1109
|
+
loop closeout includes workflow evidence
|
|
1110
|
+
loop --auto can choose workflow from openFrontier
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
### 退出标准
|
|
1114
|
+
|
|
1115
|
+
- Loop 可以运行 workflow action。
|
|
1116
|
+
- Workflow run facts 以 ref 形式进入 `rounds.jsonl`。
|
|
1117
|
+
- `loop closeout` 能引用 workflow evidence。
|
|
1118
|
+
- Loop 不直接改写 completed DAG facts。
|
|
1119
|
+
|
|
1120
|
+
---
|
|
1121
|
+
|
|
1122
|
+
## Phase 6:condition 与 loop_until
|
|
1123
|
+
|
|
1124
|
+
### 目标
|
|
1125
|
+
|
|
1126
|
+
支持单次 workflow 内的 bounded dynamic control。
|
|
1127
|
+
|
|
1128
|
+
### condition
|
|
1129
|
+
|
|
1130
|
+
`condition` 根据结构化 output 决定边:
|
|
1131
|
+
|
|
1132
|
+
```json
|
|
1133
|
+
{
|
|
1134
|
+
"id": "choose-next",
|
|
1135
|
+
"type": "condition",
|
|
1136
|
+
"dependsOn": ["run-typecheck"],
|
|
1137
|
+
"cases": [
|
|
1138
|
+
{
|
|
1139
|
+
"when": "$.nodes['run-typecheck'].output.status == 'passed'",
|
|
1140
|
+
"then": "final-report"
|
|
1141
|
+
},
|
|
1142
|
+
{
|
|
1143
|
+
"when": "$.nodes['run-typecheck'].output.status == 'failed'",
|
|
1144
|
+
"then": "analyze-errors"
|
|
1145
|
+
}
|
|
1146
|
+
],
|
|
1147
|
+
"default": "human-gate"
|
|
1148
|
+
}
|
|
1149
|
+
```
|
|
1150
|
+
|
|
1151
|
+
### loop_until
|
|
1152
|
+
|
|
1153
|
+
`loop_until` 必须 bounded:
|
|
1154
|
+
|
|
1155
|
+
```json
|
|
1156
|
+
{
|
|
1157
|
+
"id": "fix-until-tsc-passes",
|
|
1158
|
+
"type": "loop_until",
|
|
1159
|
+
"maxIterations": 5,
|
|
1160
|
+
"stopWhen": {
|
|
1161
|
+
"any": [
|
|
1162
|
+
"$.last.output.status == 'passed'",
|
|
1163
|
+
"$.stagnation.rounds >= 2"
|
|
1164
|
+
]
|
|
1165
|
+
},
|
|
1166
|
+
"body": [
|
|
1167
|
+
{ "id": "analyze-errors", "type": "agent" },
|
|
1168
|
+
{ "id": "apply-fixes", "type": "agent" },
|
|
1169
|
+
{ "id": "rerun-tsc", "type": "command" }
|
|
1170
|
+
]
|
|
1171
|
+
}
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
实现建议:
|
|
1175
|
+
|
|
1176
|
+
```text
|
|
1177
|
+
不要允许真正无限环。
|
|
1178
|
+
编译时或 runtime expansion 时展开成最多 N 轮:
|
|
1179
|
+
round_1 -> condition_1 -> round_2 -> condition_2 -> ... -> round_N
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
### 内置 profile
|
|
1183
|
+
|
|
1184
|
+
```text
|
|
1185
|
+
fix-until-check-passes
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
流程:
|
|
1189
|
+
|
|
1190
|
+
```text
|
|
1191
|
+
run-check
|
|
1192
|
+
-> loop_until(maxIterations=3)
|
|
1193
|
+
analyze-errors
|
|
1194
|
+
apply-bounded-fix
|
|
1195
|
+
rerun-check
|
|
1196
|
+
-> final-report
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
### 测试
|
|
1200
|
+
|
|
1201
|
+
```text
|
|
1202
|
+
test/dynamic-workflow-condition.test.ts
|
|
1203
|
+
test/dynamic-workflow-loop-until.test.ts
|
|
1204
|
+
condition follows expected branch
|
|
1205
|
+
condition uses default branch on no match
|
|
1206
|
+
loop_until stops on passed status
|
|
1207
|
+
loop_until stops on maxIterations
|
|
1208
|
+
loop_until detects no-progress sentinel
|
|
1209
|
+
loop_until fails validation without maxIterations
|
|
1210
|
+
```
|
|
1211
|
+
|
|
1212
|
+
### 退出标准
|
|
1213
|
+
|
|
1214
|
+
- bounded loop 可以跑 shell/static fixture。
|
|
1215
|
+
- 没有任何 unbounded cycle 能通过 validator。
|
|
1216
|
+
- loop_until 结果能进入 DAG report 与 workflow report。
|
|
1217
|
+
|
|
1218
|
+
---
|
|
1219
|
+
|
|
1220
|
+
## Phase 7:human_gate、approval、pause/resume
|
|
1221
|
+
|
|
1222
|
+
### 目标
|
|
1223
|
+
|
|
1224
|
+
把高风险 workflow 的审批点纳入 runtime,而不是依靠 prompt 约定。
|
|
1225
|
+
|
|
1226
|
+
### human_gate 语义
|
|
1227
|
+
|
|
1228
|
+
```json
|
|
1229
|
+
{
|
|
1230
|
+
"id": "approve-auth-edits",
|
|
1231
|
+
"type": "human_gate",
|
|
1232
|
+
"dependsOn": ["plan-auth-changes"],
|
|
1233
|
+
"reason": "Auth middleware edits require explicit approval",
|
|
1234
|
+
"approvalSchema": {
|
|
1235
|
+
"type": "object",
|
|
1236
|
+
"required": ["approved", "scope"],
|
|
1237
|
+
"properties": {
|
|
1238
|
+
"approved": { "type": "boolean" },
|
|
1239
|
+
"scope": { "type": "array", "items": { "type": "string" } }
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
### 命令
|
|
1246
|
+
|
|
1247
|
+
当前仓库已经有 DAG approval 命令;`human_gate` 应编译到这套机制:
|
|
1248
|
+
|
|
1249
|
+
```bash
|
|
1250
|
+
loop-agent dag approve --run-id <runId> --option <option-id> [--notes <text>]
|
|
1251
|
+
loop-agent dag reject --run-id <runId> --reason "Need manual review"
|
|
1252
|
+
loop-agent dag resume --run-id <runId>
|
|
1253
|
+
```
|
|
1254
|
+
|
|
1255
|
+
Loop integration:
|
|
1256
|
+
|
|
1257
|
+
```bash
|
|
1258
|
+
loop-agent loop add-signal <taskId> --type approval --message "Approved high severity auth fixes"
|
|
1259
|
+
loop-agent loop run <taskId> --auto
|
|
1260
|
+
```
|
|
1261
|
+
|
|
1262
|
+
### 测试
|
|
1263
|
+
|
|
1264
|
+
```text
|
|
1265
|
+
test/dynamic-workflow-human-gate.test.ts
|
|
1266
|
+
human_gate pauses run
|
|
1267
|
+
approval resumes descendants
|
|
1268
|
+
rejection marks workflow blocked
|
|
1269
|
+
loop signal can satisfy pending gate
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
### 退出标准
|
|
1273
|
+
|
|
1274
|
+
- 高风险 workflow 可以在 gate 暂停。
|
|
1275
|
+
- approval/rejection 都进入 audit trail。
|
|
1276
|
+
- Loop 能记录 pending approval 并 resume。
|
|
1277
|
+
|
|
1278
|
+
---
|
|
1279
|
+
|
|
1280
|
+
## Phase 8:saved workflows、replay、operator UX
|
|
1281
|
+
|
|
1282
|
+
### 目标
|
|
1283
|
+
|
|
1284
|
+
把 workflow 从一次性 plan 变成可复用、可 diff、可 replay 的产品能力。
|
|
1285
|
+
|
|
1286
|
+
### 保存位置
|
|
1287
|
+
|
|
1288
|
+
```text
|
|
1289
|
+
.loop-agent/workflows/ # repo shared
|
|
1290
|
+
~/.loop-agent/workflows/ # personal
|
|
1291
|
+
.harness/tasks/<taskId>/workflows/ # task-local generated plans
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1294
|
+
### 命令
|
|
1295
|
+
|
|
1296
|
+
```bash
|
|
1297
|
+
loop-agent workflow list
|
|
1298
|
+
loop-agent workflow inspect pr-review
|
|
1299
|
+
loop-agent workflow run pr-review --args '{"base":"main","head":"HEAD"}'
|
|
1300
|
+
loop-agent workflow save --from .harness/tasks/T/workflows/planned/pr-review.workflow.json --name pr-review
|
|
1301
|
+
loop-agent workflow diff pr-review --against .harness/tasks/T/workflows/planned/pr-review.workflow.json
|
|
1302
|
+
loop-agent workflow replay <runId>
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
DAG operator UX:
|
|
1306
|
+
|
|
1307
|
+
```bash
|
|
1308
|
+
loop-agent dag status --run-id <runId>
|
|
1309
|
+
loop-agent dag doctor
|
|
1310
|
+
loop-agent dag report --run-id <runId> --json --lifecycle all
|
|
1311
|
+
loop-agent dag decision inspect --run-id <runId>
|
|
1312
|
+
loop-agent dag decision validate --run-id <runId>
|
|
1313
|
+
loop-agent dag resume --run-id <runId>
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
未来如果需要更细粒度 operator UX,再新增 `inspect-node`、`restart-node`、`stop` 等命令;不要在 saved workflow 阶段顺手扩大 DAG control plane。
|
|
1317
|
+
|
|
1318
|
+
### 测试
|
|
1319
|
+
|
|
1320
|
+
```text
|
|
1321
|
+
test/workflow-list.test.ts
|
|
1322
|
+
test/workflow-run.test.ts
|
|
1323
|
+
test/workflow-save.test.ts
|
|
1324
|
+
test/workflow-replay.test.ts
|
|
1325
|
+
test/dag-operator-status.test.ts
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
### 退出标准
|
|
1329
|
+
|
|
1330
|
+
- workflow 可保存、可复用、可传 args。
|
|
1331
|
+
- replay 不重复已完成 artifacts,或明确说明哪些节点重新执行。
|
|
1332
|
+
- operator 能定位失败 node、查看 expansion、查看 verifier 结果。
|
|
1333
|
+
|
|
1334
|
+
---
|
|
1335
|
+
|
|
1336
|
+
## Phase 9:大规模迁移与 worktree/shard execution
|
|
1337
|
+
|
|
1338
|
+
### 目标
|
|
1339
|
+
|
|
1340
|
+
支持更高风险、更高价值的场景:多文件 migration。
|
|
1341
|
+
|
|
1342
|
+
### 原则
|
|
1343
|
+
|
|
1344
|
+
- 不允许多个 writer agent 在同一工作树无隔离并发写。
|
|
1345
|
+
- 使用 shard / worktree / delegate / harvest 模式。
|
|
1346
|
+
- 每个 shard 有独立 verification。
|
|
1347
|
+
- merge patch 前做 conflict 和 test gate。
|
|
1348
|
+
|
|
1349
|
+
### Workflow pattern
|
|
1350
|
+
|
|
1351
|
+
```text
|
|
1352
|
+
discover-targets
|
|
1353
|
+
-> shard-targets
|
|
1354
|
+
-> map_agent(migrate-shard-in-isolated-worktree)
|
|
1355
|
+
-> map_agent(verify-shard)
|
|
1356
|
+
-> reduce_agent(merge-plan)
|
|
1357
|
+
-> human_gate(approve-merge)
|
|
1358
|
+
-> apply-merge
|
|
1359
|
+
-> final-shell-verify
|
|
1360
|
+
```
|
|
1361
|
+
|
|
1362
|
+
### 测试
|
|
1363
|
+
|
|
1364
|
+
```text
|
|
1365
|
+
test/dynamic-workflow-sharded-migration.test.ts
|
|
1366
|
+
writeSet conflicts rejected
|
|
1367
|
+
shards get isolated workspaces
|
|
1368
|
+
failed shard does not block successful shard artifacts
|
|
1369
|
+
merge requires human_gate when writeSet is broad
|
|
1370
|
+
```
|
|
1371
|
+
|
|
1372
|
+
### 退出标准
|
|
1373
|
+
|
|
1374
|
+
- 可以安全 dogfood 一个低风险 repo migration。
|
|
1375
|
+
- 每个 shard 的 patch、verification、failure reason 独立可追踪。
|
|
1376
|
+
- 最终 merge 有明确 approval 和 shell verification。
|
|
1377
|
+
|
|
1378
|
+
---
|
|
1379
|
+
|
|
1380
|
+
## 6. 建议 MVP 顺序
|
|
1381
|
+
|
|
1382
|
+
不要先做自动修代码。MVP 应分成两层:
|
|
1383
|
+
|
|
1384
|
+
1. **工程 MVP**:`WorkflowSpec -> validate -> compile -> dag validate`,不要求 runtime dynamic expansion。
|
|
1385
|
+
2. **产品 MVP**:read-only PR review,因为它最能展示 Dynamic Workflow 的价值,同时风险低。
|
|
1386
|
+
|
|
1387
|
+
这样安排的原因是:当前 `run-dag` 还没有动态插入节点的 seam。先做工程 MVP 可以验证 Interface 和 compiler depth,再进入 map/verify/reduce 的产品 MVP。
|
|
1388
|
+
|
|
1389
|
+
### 6.1 工程 MVP:static workflow compile
|
|
1390
|
+
|
|
1391
|
+
目标:
|
|
1392
|
+
|
|
1393
|
+
```text
|
|
1394
|
+
simple-readonly-workflow.workflow.json
|
|
1395
|
+
-> dag workflow-validate
|
|
1396
|
+
-> dag workflow-compile
|
|
1397
|
+
-> dag validate --strict-governance
|
|
1398
|
+
```
|
|
1399
|
+
|
|
1400
|
+
验收:
|
|
1401
|
+
|
|
1402
|
+
```bash
|
|
1403
|
+
loop-agent dag workflow-validate --workflow test/fixtures/dynamic/simple-readonly.workflow.json --strict-governance
|
|
1404
|
+
loop-agent dag workflow-compile --workflow test/fixtures/dynamic/simple-readonly.workflow.json --output /tmp/simple-readonly.dag.json
|
|
1405
|
+
loop-agent dag validate --dag /tmp/simple-readonly.dag.json --strict-models --strict-governance
|
|
1406
|
+
```
|
|
1407
|
+
|
|
1408
|
+
退出标准:
|
|
1409
|
+
|
|
1410
|
+
- 不改 `run-dag`。
|
|
1411
|
+
- 编译产物通过现有 DAG validator。
|
|
1412
|
+
- compile manifest 能解释每个 workflow node 对应哪个 DAG task。
|
|
1413
|
+
|
|
1414
|
+
### 6.2 产品 MVP:PR Review Workflow
|
|
1415
|
+
|
|
1416
|
+
MVP workflow:
|
|
1417
|
+
|
|
1418
|
+
```text
|
|
1419
|
+
discover-changed-files
|
|
1420
|
+
-> map_agent(review-each-file)
|
|
1421
|
+
-> verify_agent(verify-each-finding)
|
|
1422
|
+
-> reduce_agent(final-ranked-summary)
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
### 为什么选它
|
|
1426
|
+
|
|
1427
|
+
- 文件数量运行时才知道,能验证 dynamic expansion。
|
|
1428
|
+
- findings 数量运行时才知道,能验证 second-order expansion。
|
|
1429
|
+
- verifier/reducer 能展示质量闭环。
|
|
1430
|
+
- read-only,风险低。
|
|
1431
|
+
- 最终 report 容易人工评估。
|
|
1432
|
+
- 可后续接 Loop:如果有 verified high severity findings,下一轮再进入 fix workflow。
|
|
1433
|
+
- read-only PR review 不要求 writer concurrency,因此不会先触发多 writer/worktree 风险。
|
|
1434
|
+
|
|
1435
|
+
### MVP 验收
|
|
1436
|
+
|
|
1437
|
+
```bash
|
|
1438
|
+
loop-agent new-task pr-review-demo "Review changed files"
|
|
1439
|
+
loop-agent dag workflow-plan pr-review-demo --profile pr-review --output .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json
|
|
1440
|
+
loop-agent dag workflow-validate --workflow .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json --strict-governance
|
|
1441
|
+
loop-agent dag workflow-compile --workflow .harness/tasks/pr-review-demo/workflows/planned/pr-review.workflow.json --output .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json
|
|
1442
|
+
loop-agent dag validate --dag .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json --strict-governance
|
|
1443
|
+
loop-agent run-dag --dag .harness/tasks/pr-review-demo/workflows/compiled/pr-review.dag.json --cwd .
|
|
1444
|
+
```
|
|
1445
|
+
|
|
1446
|
+
验收结果:
|
|
1447
|
+
|
|
1448
|
+
- `.harness/dag-runs/.../expansions/review-each-file.expansion.json` 存在。
|
|
1449
|
+
- `.harness/dag-runs/.../expansions/verify-findings.expansion.json` 存在。
|
|
1450
|
+
- final report 区分 verified / uncertain / refuted。
|
|
1451
|
+
- run-dag report 可引用到每个 verifier artifact。
|
|
1452
|
+
- workflow-level report 可复制给用户。
|
|
1453
|
+
|
|
1454
|
+
---
|
|
1455
|
+
|
|
1456
|
+
## 7. 测试与验证金字塔
|
|
1457
|
+
|
|
1458
|
+
### 7.1 Unit tests
|
|
1459
|
+
|
|
1460
|
+
```text
|
|
1461
|
+
WorkflowSpec parser
|
|
1462
|
+
schema validation
|
|
1463
|
+
risk analyzer
|
|
1464
|
+
JSONPath itemsFrom resolver
|
|
1465
|
+
map expansion
|
|
1466
|
+
loop_until expansion
|
|
1467
|
+
artifact ref resolver
|
|
1468
|
+
Finding / Verification schema
|
|
1469
|
+
```
|
|
1470
|
+
|
|
1471
|
+
### 7.2 Golden tests
|
|
1472
|
+
|
|
1473
|
+
输入:
|
|
1474
|
+
|
|
1475
|
+
```text
|
|
1476
|
+
*.workflow.json
|
|
1477
|
+
```
|
|
1478
|
+
|
|
1479
|
+
输出:
|
|
1480
|
+
|
|
1481
|
+
```text
|
|
1482
|
+
*.compiled-dag.json
|
|
1483
|
+
*.validation.json
|
|
1484
|
+
*.risk.json
|
|
1485
|
+
```
|
|
1486
|
+
|
|
1487
|
+
目的:保证 IR 编译稳定、可 diff。
|
|
1488
|
+
|
|
1489
|
+
### 7.3 Dry-run tests
|
|
1490
|
+
|
|
1491
|
+
```bash
|
|
1492
|
+
loop-agent dag workflow-validate --workflow fixture.workflow.json
|
|
1493
|
+
loop-agent dag workflow-compile --workflow fixture.workflow.json --output /tmp/fixture.dag.json
|
|
1494
|
+
loop-agent dag validate --dag /tmp/fixture.dag.json --strict-governance
|
|
1495
|
+
```
|
|
1496
|
+
|
|
1497
|
+
### 7.4 Static executor integration tests
|
|
1498
|
+
|
|
1499
|
+
用 `static` executor 模拟:
|
|
1500
|
+
|
|
1501
|
+
- discover files output。
|
|
1502
|
+
- reviewer findings output。
|
|
1503
|
+
- verifier status output。
|
|
1504
|
+
- reducer report output。
|
|
1505
|
+
|
|
1506
|
+
不依赖外部模型,CI 稳定。
|
|
1507
|
+
|
|
1508
|
+
### 7.5 Shell-only smoke tests
|
|
1509
|
+
|
|
1510
|
+
用只读 command:
|
|
1511
|
+
|
|
1512
|
+
```bash
|
|
1513
|
+
git diff --name-only main...HEAD
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
测试真实 command allowlist、cwd、stdout parsing、artifact。
|
|
1517
|
+
|
|
1518
|
+
### 7.6 Model executor dogfood tests
|
|
1519
|
+
|
|
1520
|
+
在本地或非 CI 环境跑:
|
|
1521
|
+
|
|
1522
|
+
- Pi reviewer。
|
|
1523
|
+
- Pi verifier。
|
|
1524
|
+
- Cursor read-only reviewer。
|
|
1525
|
+
- 小 repo / 小目录。
|
|
1526
|
+
|
|
1527
|
+
### 7.7 Loop integration tests
|
|
1528
|
+
|
|
1529
|
+
验证:
|
|
1530
|
+
|
|
1531
|
+
- workflow action append round。
|
|
1532
|
+
- workflow report ref 进入 closeout。
|
|
1533
|
+
- signal -> workflow input。
|
|
1534
|
+
- failureStreak 影响 `loop --auto`。
|
|
1535
|
+
- Loop 不改写 completed DAG facts。
|
|
1536
|
+
|
|
1537
|
+
---
|
|
1538
|
+
|
|
1539
|
+
## 8. 风险与治理策略
|
|
1540
|
+
|
|
1541
|
+
### 8.1 禁止任意代码作为 workflow IR
|
|
1542
|
+
|
|
1543
|
+
不要支持:
|
|
1544
|
+
|
|
1545
|
+
```json
|
|
1546
|
+
{ "eval": "some JavaScript" }
|
|
1547
|
+
```
|
|
1548
|
+
|
|
1549
|
+
也不要支持:
|
|
1550
|
+
|
|
1551
|
+
```json
|
|
1552
|
+
{ "shell": "{{model_generated_command}}" }
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
表达力不够时,新增 bounded primitive:
|
|
1556
|
+
|
|
1557
|
+
```text
|
|
1558
|
+
agent
|
|
1559
|
+
map_agent
|
|
1560
|
+
verify_agent
|
|
1561
|
+
reduce_agent
|
|
1562
|
+
command
|
|
1563
|
+
condition
|
|
1564
|
+
loop_until
|
|
1565
|
+
human_gate
|
|
1566
|
+
artifact_transform
|
|
1567
|
+
subworkflow
|
|
1568
|
+
```
|
|
1569
|
+
|
|
1570
|
+
### 8.2 强制 limits
|
|
1571
|
+
|
|
1572
|
+
WorkflowSpec 必须有默认 limits,且 runtime 有硬上限:
|
|
1573
|
+
|
|
1574
|
+
```json
|
|
1575
|
+
{
|
|
1576
|
+
"maxConcurrency": 8,
|
|
1577
|
+
"maxAgentRuns": 100,
|
|
1578
|
+
"maxExpandedNodes": 200,
|
|
1579
|
+
"maxRetriesPerNode": 1,
|
|
1580
|
+
"maxIterations": 3,
|
|
1581
|
+
"maxWallClockMinutes": 30
|
|
1582
|
+
}
|
|
1583
|
+
```
|
|
1584
|
+
|
|
1585
|
+
不能相信 planner 自己节制。
|
|
1586
|
+
|
|
1587
|
+
### 8.3 权限与写入范围
|
|
1588
|
+
|
|
1589
|
+
- read-only workflow 默认风险低。
|
|
1590
|
+
- edits 必须声明 `allowedPaths` / `forbiddenPaths` / `writeSet`。
|
|
1591
|
+
- 同 rank writeSet 冲突必须 fail。
|
|
1592
|
+
- broad writeSet 必须 human_gate。
|
|
1593
|
+
- command 必须 allowlist。
|
|
1594
|
+
- network 默认 deny。
|
|
1595
|
+
- secrets 默认不可见。
|
|
1596
|
+
|
|
1597
|
+
### 8.4 Verifier 独立性
|
|
1598
|
+
|
|
1599
|
+
- producer 不能 verify 自己的 finding。
|
|
1600
|
+
- verifier 只看 finding、evidence、target artifact。
|
|
1601
|
+
- reducer 不新增 facts。
|
|
1602
|
+
- final report 默认只包含 verified findings。
|
|
1603
|
+
|
|
1604
|
+
### 8.5 Completed facts 不可改写
|
|
1605
|
+
|
|
1606
|
+
- DAG run artifact 是事实源。
|
|
1607
|
+
- Workflow report 可以 summarize,但不改写 node output。
|
|
1608
|
+
- Loop 可以引用 workflow/DAG facts,但不改写 completed DAG facts。
|
|
1609
|
+
|
|
1610
|
+
---
|
|
1611
|
+
|
|
1612
|
+
## 9. 推荐 PR 顺序
|
|
1613
|
+
|
|
1614
|
+
### PR 1:文档与对象边界
|
|
1615
|
+
|
|
1616
|
+
- 添加/更新本文档。
|
|
1617
|
+
- 必要时更新 CLI help 文案,但不要在没有实现的情况下承诺 `workflow` 顶层命令。
|
|
1618
|
+
- 明确 DAG / Workflow / Loop 分层。
|
|
1619
|
+
- 明确 Level 1 fallback 已删除,不能作为 workflow 基础。
|
|
1620
|
+
|
|
1621
|
+
### PR 2:WorkflowSpec schema + validator
|
|
1622
|
+
|
|
1623
|
+
- 新增 `src/workflows/dynamic/spec.ts`。
|
|
1624
|
+
- 新增 validator。
|
|
1625
|
+
- 加 fixture tests。
|
|
1626
|
+
- 新增 `dag workflow-validate` 实验入口。
|
|
1627
|
+
|
|
1628
|
+
### PR 3:workflow compile v0
|
|
1629
|
+
|
|
1630
|
+
- 支持 agent / command / reduce / artifact_transform。
|
|
1631
|
+
- 产出 existing AgentDAG。
|
|
1632
|
+
- 通过 existing `dag validate`。
|
|
1633
|
+
- 产出 compile manifest 或扩展后的稳定 `DagSpec` origin 字段。
|
|
1634
|
+
|
|
1635
|
+
### PR 4:map_agent dynamic expansion
|
|
1636
|
+
|
|
1637
|
+
- 支持 `itemsFrom`。
|
|
1638
|
+
- 写 expansion manifest。
|
|
1639
|
+
- 支持 resume 不重复展开。
|
|
1640
|
+
- 明确 runner expansion seam,不隐式改写 completed DAG facts。
|
|
1641
|
+
|
|
1642
|
+
### PR 5:verify_agent + Finding/Verification artifact
|
|
1643
|
+
|
|
1644
|
+
- 标准化 finding / verification。
|
|
1645
|
+
- reducer 默认只包含 verified。
|
|
1646
|
+
|
|
1647
|
+
### PR 6:pr-review profile
|
|
1648
|
+
|
|
1649
|
+
- read-only MVP。
|
|
1650
|
+
- fixture + static executor + optional model dogfood。
|
|
1651
|
+
|
|
1652
|
+
### PR 7:loop workflow action
|
|
1653
|
+
|
|
1654
|
+
- `loop run --action workflow`。
|
|
1655
|
+
- round 记录 workflowRef / runRef / reportRef。
|
|
1656
|
+
- closeout 汇总 workflow evidence。
|
|
1657
|
+
|
|
1658
|
+
### PR 8:condition / loop_until
|
|
1659
|
+
|
|
1660
|
+
- bounded loop。
|
|
1661
|
+
- fix-until-check-passes profile。
|
|
1662
|
+
|
|
1663
|
+
### PR 9:workflow save / run / replay
|
|
1664
|
+
|
|
1665
|
+
- `.loop-agent/workflows/`。
|
|
1666
|
+
- `workflow list/inspect/run/save/replay`。
|
|
1667
|
+
|
|
1668
|
+
### PR 10:operator UX
|
|
1669
|
+
|
|
1670
|
+
- 优先增强现有 status / doctor / report / decision / resume。
|
|
1671
|
+
- 只有在真实操作痛点出现后,再考虑 inspect-node / restart-node / stop。
|
|
1672
|
+
|
|
1673
|
+
---
|
|
1674
|
+
|
|
1675
|
+
## 10. 非目标
|
|
1676
|
+
|
|
1677
|
+
短期不要做:
|
|
1678
|
+
|
|
1679
|
+
- 完整 JS workflow runtime。
|
|
1680
|
+
- 任意代码 eval。
|
|
1681
|
+
- 无限制 autonomous loop。
|
|
1682
|
+
- 大规模自动改代码。
|
|
1683
|
+
- 多 writer agent 在同一 worktree 并发写。
|
|
1684
|
+
- 用 Loop 替代 DAG runner。
|
|
1685
|
+
- 用 reducer 重新审计 facts。
|
|
1686
|
+
- 用模型自述替代 shell verification。
|
|
1687
|
+
- 在 IR 未稳定前新增顶层 `workflow` 公共命令。
|
|
1688
|
+
- 为了支持 Dynamic Workflow 恢复 Level 1 顺序工作流。
|
|
1689
|
+
|
|
1690
|
+
---
|
|
1691
|
+
|
|
1692
|
+
## 11. 成功标准
|
|
1693
|
+
|
|
1694
|
+
### 技术成功标准
|
|
1695
|
+
|
|
1696
|
+
- WorkflowSpec 是稳定、可审查、可 diff 的 artifact。
|
|
1697
|
+
- Dynamic workflow 可以编译成现有 Agent DAG。
|
|
1698
|
+
- compile manifest 或 `DagSpec` origin 字段能追踪 workflow node 到 DAG task 的映射。
|
|
1699
|
+
- map_agent 可以根据上游 output 动态展开。
|
|
1700
|
+
- verify_agent 可以独立验证 findings。
|
|
1701
|
+
- reducer 可以输出 verified-first report。
|
|
1702
|
+
- Loop 可以记录 workflow run evidence。
|
|
1703
|
+
- 所有阶段都有 deterministic tests。
|
|
1704
|
+
|
|
1705
|
+
### 产品成功标准
|
|
1706
|
+
|
|
1707
|
+
用户可以这样理解系统:
|
|
1708
|
+
|
|
1709
|
+
```text
|
|
1710
|
+
普通任务:用 DAG runtime。
|
|
1711
|
+
一次复杂并行任务:用 Dynamic Workflow。
|
|
1712
|
+
长期多轮任务:用 Loop Task 管多个 workflow/DAG/shell/review round。
|
|
1713
|
+
```
|
|
1714
|
+
|
|
1715
|
+
### 治理成功标准
|
|
1716
|
+
|
|
1717
|
+
- 高风险 workflow 必须审批。
|
|
1718
|
+
- 所有 fan-out 有硬上限。
|
|
1719
|
+
- 所有 shell 命令可审计。
|
|
1720
|
+
- 所有写入范围可审计。
|
|
1721
|
+
- 所有 completed facts 有 artifact ref。
|
|
1722
|
+
- closeout 有 verification evidence。
|
|
1723
|
+
|
|
1724
|
+
---
|
|
1725
|
+
|
|
1726
|
+
## 12. 最终定位文案
|
|
1727
|
+
|
|
1728
|
+
中文:
|
|
1729
|
+
|
|
1730
|
+
> `loop-agent` 是一个 repo-local AI coding workflow runtime。它以 DAG runtime 作为执行内核,在其上通过 Dynamic Workflow DAG Engine 把复杂任务动态编译为可验证的 Agent DAG;对于长期目标,Loop Task 将多次 workflow run、DAG run、shell verification、人工反馈和 closeout 串成可恢复、可审查、可交付的工程闭环。
|
|
1731
|
+
|
|
1732
|
+
英文:
|
|
1733
|
+
|
|
1734
|
+
> `loop-agent` is a repo-local AI coding workflow runtime. Its DAG runtime executes concrete Agent DAGs with artifacts and verification. The Dynamic Workflow DAG Engine compiles high-level workflow specs into expanded, verifiable Agent DAGs. For long-running objectives, Loop Task coordinates multiple workflow, DAG, shell, and review rounds into a recoverable and auditable delivery loop.
|
|
1735
|
+
|
|
1736
|
+
---
|
|
1737
|
+
|
|
1738
|
+
## 参考来源
|
|
1739
|
+
|
|
1740
|
+
[1] Anthropic Claude Code Docs, “Orchestrate subagents at scale with dynamic workflows”, accessed 2026-07-04.
|
|
1741
|
+
https://code.claude.com/docs/en/workflows
|
|
1742
|
+
|
|
1743
|
+
[2] 用户上传文档:`粘贴的 markdown (1).md`,关于用 DAG JSON 复刻 Claude Dynamic Workflows 的设计说明。
|
|
1744
|
+
|
|
1745
|
+
[3] 用户上传文档:`2026-07-02-repository-analysis.md`,关于当前 `loop-agent` 仓库结构、DAG 主路径、Loop 语义、治理边界与健康度的分析报告。
|
|
1746
|
+
|
|
1747
|
+
[4] 当前源码仓库历史 completed execution plan,关于删除 Level 1 fallback、抽取 shell verification、建立 DAG-oriented task read model 的完成记录;发布包只携带 execution plan 目录说明,不携带具体历史计划正文。
|
|
1748
|
+
|
|
1749
|
+
[5] 当前源码复核:`src/workflows/dag/types.ts`、`src/workflows/dag/validate.ts`、`src/workflows/dag/runner.ts`、`src/workflows/loop/actions.ts`、`src/task/read-model.ts`、`src/cli/catalog.ts`。
|