OpenForge v2
PRD-to-implementation pipeline for OpenClaw.
OpenForge takes a structured PRD (Product Requirements Document) and executes it through staged phases: parallel where possible, with model routing, quality gates, and automatic review-to-fix loops. No Python, no custom agent registration, no install step — runs entirely through native OpenClaw tools (sessions_spawn, exec, read, write).
What OpenForge Does
- 1. Parses a PRD markdown file into phases and tasks
- Spawns sub-agents for phases that can run in parallel
- Routes each task to the right model tier (Haiku → Sonnet/GPT → Opus)
- Gates each phase: pass/fail check after completion
- Auto-fixes: when a review phase finds issues, a fix agent is spawned and the review re-runs (up to 3 cycles)
- Escalates when retries are exhausted or a gate fails hard
What OpenForge Does NOT Do
- - Does not run a CLI — it IS the agent execution loop
- Does not add an OS-level sandbox beyond the agent's existing workspace constraints
- Does not require or manage custom agent registration
Safety & Scope
- - OpenForge operates within the user's configured workspace directory
- Sub-agents inherit the same workspace constraints as the orchestrator
- PRD trust model: PRDs define what code to write and what shell commands to run as gates. Review PRDs before execution — they have the same trust level as code you would run. Do not execute PRDs from untrusted sources.
- Secret safety: Never include secrets, API keys, or credentials in PRD files. PRD content is passed to sub-agents verbatim. OpenForge does not scan for embedded secrets — keep them in environment variables.
- Gate commands: Gate commands are run via
exec in the working directory. Only build/test/lint commands are expected — for example: npm test, npm run build, pytest, cargo test, go test, ruff check. Before executing any gate, OpenForge validates that the command does not contain shell metacharacters (;, &&, ||, |, $(, backticks, >, <) unless the PRD explicitly marks the phase with Shell-Gate: true. Gates that fail this check are rejected with an error. Review all gate commands in your PRD before execution. - No credentials are bundled, stored, or transmitted by OpenForge
- All execution is local to the OpenClaw agent environment
- No data is sent to external endpoints beyond your configured AI model providers
PRD Format
A PRD is a markdown file. OpenForge reads it top-to-bottom and extracts phases.
Minimal PRD
CODEBLOCK0
PRD Fields
| Field | Required | Values | Meaning |
|---|
| INLINECODE19 | No | INLINECODE20 , sonnet, gpt, INLINECODE23 | Model tier for this phase |
| INLINECODE24 |
No |
impl,
review,
extract | Phase type; controls prompting style |
|
[parallel] | No | Flag in phase header | Phase can run alongside other
[parallel] phases |
|
depends: | No | Phase name(s) | This phase waits for named phases to complete |
|
Gate: | No | Shell command or description | Must pass before next phase starts |
|
Max-Retries: | No | Integer (default: 2) | Gate failure retries before escalation |
|
Shell-Gate: | No |
true | Allow shell metacharacters in gate command (use only for trusted, reviewed gates) |
Phase Types
- -
impl (default) — implementation work; agent writes code, files, configs review — evaluative; agent produces a structured findings report; triggers auto-fix loop if issues foundextract — lightweight parsing or summarization; routed to Haiku
Model Routing
| Alias | Maps To | Use For |
|---|
| INLINECODE38 | INLINECODE39 / cheapest available | Extraction, parsing, structured output |
| INLINECODE40 |
claude-sonnet | Implementation, research, multi-file work |
|
gpt |
gpt-4o or equivalent | Alternative implementation path |
|
opus |
claude-opus | Judgment, review, final quality gate |
OpenForge maps these aliases to whatever models are configured in your OpenClaw instance. If a model alias isn't available, Sonnet is used as the safe fallback.
Execution Protocol
When OpenForge is triggered, follow this exact sequence:
Step 1 — Parse the PRD
Read the PRD file. Extract:
- - Title and objective
- All phases in order, with their model, type, dependencies, gate, and task list
- Identify which phases are
[parallel] and which have depends: constraints
Build a dependency graph. Phases with no depends: and tagged [parallel] can be spawned simultaneously.
Horizon-Bounded Decomposition: Estimate the total step count across all phases. If the PRD contains > 40 estimated steps, decompose complex phases into sub-phases of ≤ 20 steps each before execution. If 20–40 steps, insert a midpoint quality checkpoint between phases. Under 20 steps, execute directly. This prevents accuracy collapse on long-horizon tasks (research: LORE benchmark shows accuracy → 0 past 120 steps).
Step 2 — Pre-flight check
Before spawning anything:
- - Confirm the PRD has at least one phase
- Confirm all
depends: references name real phases - Confirm the working directory exists (if specified)
- If any check fails: halt and report the problem clearly
Step 3 — Execute phases
For each wave of phases (phases whose dependencies are all satisfied):
If multiple phases are [parallel]: spawn them as sub-agents simultaneously using sessions_spawn. Pass each sub-agent:
- - The full PRD context
- Its specific phase tasks
- The model to use
- The gate command (if any)
- The working directory
If a phase has depends:: wait for all named phases to complete before spawning.
Sequential phases (no [parallel] tag): run one at a time in declaration order.
Step 4 — Gate evaluation
After each phase completes:
- 1. If a gate command is specified:
-
Validate the gate command first. Reject commands containing shell metacharacters (
;,
&&,
||,
|,
$(, `
`
, >
, <
) unless the phase includes Shell-Gate: true
. This prevents accidental or malicious arbitrary shell execution from PRD content.
- Run the validated gate command with exec
2. **Erosion check (code phases):** If the phase produced code, measure structural complexity. If cyclomatic complexity mass in high-CC functions (CC > 10) increased > 5% compared to the prior phase's baseline, flag for review or force a refactoring sub-phase before proceeding. This prevents quality degradation across sequential phases (research: SlopCodeBench shows structural erosion in 80% of agent trajectories).
3. If the gate passes (exit 0): mark phase complete, proceed
4. If it fails: retry the phase up to Max-Retries
times (default: 2), passing the failure output as context
5. If retries exhausted: escalate to Corbin and halt
### Step 5 — Review-to-fix loop
For phases with Type: review
:
1. The review agent produces a structured findings report
2. Parse the report for blocking/required issues
3. If issues exist:
- Spawn a **fix sub-agent** (same model tier as the implementation phase, or Sonnet default) with the findings as context
- After fix agent completes, re-run the review phase
- Repeat up to 3 cycles
4. If issues persist after 3 cycles: escalate with full findings history
5. If no blocking issues: mark review phase complete
**Review agent prompt structure:**
CODEBLOCK1
**Fix agent prompt structure:**
CODEBLOCK2
### Step 6 — Completion
When all phases pass their gates:
1. Write a completion summary to .openforge/run-{timestamp}.md
in the working directory (if a cwd was specified)
2. Report success with phase outcomes and any escalations that occurred
3. If any phases were skipped or escalated, report them explicitly
---
## Sub-agent Prompting
When spawning a sub-agent for a phase, include:
CODEBLOCK3
---
## Escalation Protocol
Escalate to the human (Corbin / operator) when:
1. A gate fails after all retries are exhausted
2. A review-to-fix loop hits 3 cycles without reaching PASS
3. The PRD has structural errors that prevent execution
4. A phase sub-agent returns an error that can't be recovered
5. A phase declares escalate: true
explicitly
Escalation message format:
CODEBLOCK4
---
## Security Constraints
- Sub-agents run with the same permissions as the parent agent within the workspace directory
- Gate commands are run with exec
in the working directory. Review gate commands before running against production systems. Avoid destructive commands (e.g., rm -rf
).
- OpenForge writes one artifact (.openforge/run-{timestamp}.md
) to the working directory. No other writes are made by the orchestrator itself.
- No network connections are made by OpenForge itself — only your configured AI model providers are contacted via the OpenClaw agent interface
---
## Example: Full Parallel PRD
CODEBLOCK5
In this PRD:
- research
and design
run **in parallel** (no dependencies, both tagged [parallel]
)
- implement
waits for both, then runs with Sonnet
- security-review
runs last with Opus, triggers auto-fix loop if issues are found
---
## Limitations (v2)
- Parallel phase results are collected via sub-agent completion events — if a sub-agent times out, that phase's output may be missing
- Review-to-fix loops use the same working directory; if the fix agent introduces regressions, OpenForge will catch them at the gate but won't automatically revert
- Gate commands run in the working directory with no isolation — avoid destructive commands (e.g., rm -rf
)
- No persistent run state across sessions — if the parent agent session ends mid-run, the run cannot be resumed (sub-agents completing after session end will still announce results but the orchestrator won't act on them)
- Model alias resolution depends on your OpenClaw instance's configured models; if opus
isn't available, Sonnet will be used silently
---
## Quick Reference
| What you want | How to trigger |
|---------------|---------------|
| Run a PRD | "Run this PRD: [paste or path]" |
| Dry-run (plan only) | "Plan this PRD without executing" |
| Run a single phase | "Run only the implement
phase of this PRD" |
| Skip a phase | Add Skip: true
to the phase header |
| Force a model | Add Model: opus
to any phase |
| Cap retries | Add Max-Retries: 1
to a phase |
| Parallel phases | Add [parallel]` to phase header |
OpenForge v2
面向OpenClaw的PRD到实现流水线。
OpenForge接收结构化的PRD(产品需求文档),并通过分阶段的方式执行:尽可能并行执行,包含模型路由、质量门禁以及自动审查修复循环。无需Python,无需自定义代理注册,无需安装步骤——完全通过OpenClaw原生工具(sessions_spawn、exec、read、write)运行。
OpenForge的功能
- 1. 解析 PRD Markdown文件,将其分解为多个阶段和任务
- 生成子代理 用于可以并行运行的阶段
- 路由 每个任务到正确的模型层级(Haiku → Sonnet/GPT → Opus)
- 门控 每个阶段:完成后进行通过/失败检查
- 自动修复:当审查阶段发现问题时,生成一个修复代理并重新运行审查(最多3个周期)
- 升级 当重试次数耗尽或门禁严重失败时
OpenForge不做什么
- - 不运行CLI——它本身就是代理执行循环
- 不会在代理现有工作区约束之外添加操作系统级沙箱
- 不需要或管理自定义代理注册
安全性与范围
- - OpenForge在用户配置的工作区目录内运行
- 子代理继承与编排器相同的工作区约束
- PRD信任模型: PRD定义了要编写的代码以及作为门禁运行的Shell命令。在执行前审查PRD——它们具有与你将要运行的代码相同的信任级别。不要执行来自不可信来源的PRD。
- 密钥安全: 切勿在PRD文件中包含密钥、API密钥或凭据。PRD内容会原封不动地传递给子代理。OpenForge不会扫描嵌入的密钥——请将它们保存在环境变量中。
- 门禁命令: 门禁命令通过exec在工作目录中运行。预期只有构建/测试/代码检查命令——例如:npm test、npm run build、pytest、cargo test、go test、ruff check。在执行任何门禁之前,OpenForge会验证该命令是否包含Shell元字符(;、&&、||、|、$(、反引号、>、<),除非PRD明确使用Shell-Gate: true标记该阶段。未通过此检查的门禁将被拒绝并报错。在执行前,请审查PRD中的所有门禁命令。
- OpenForge不会捆绑、存储或传输任何凭据
- 所有执行均在OpenClaw代理环境本地进行
- 除了你配置的AI模型提供商外,不会向外部端点发送任何数据
PRD格式
PRD是一个Markdown文件。OpenForge从上到下读取它并提取阶段。
最小PRD示例
markdown
PRD: 我的功能
目标
为API构建一个CSV导出端点。
阶段
阶段: 脚手架 [parallel]
模型: sonnet
任务:
- - 在 src/routes/export.ts 中创建路由处理器
- 在 src/lib/csv.ts 中编写CSV序列化器
门禁: npm run build 必须通过
阶段: 测试 [depends: 脚手架]
模型: sonnet
任务:
- - 为CSV序列化器编写单元测试
- 为导出端点编写集成测试
门禁: npm test 必须通过
阶段: 审查 [depends: 测试]
模型: opus
类型: review
任务:
- - 审查完整实现的正确性、边缘情况和安全性
- 检查对格式错误输入的错误处理
门禁: 审查必须发现零个阻塞性问题
PRD字段
| 字段 | 必需 | 值 | 含义 |
|---|
| Model: | 否 | haiku, sonnet, gpt, opus | 此阶段的模型层级 |
| Type: |
否 | impl, review, extract | 阶段类型;控制提示风格 |
| [parallel] | 否 | 阶段头中的标志 | 阶段可以与其他 [parallel] 阶段同时运行 |
| depends: | 否 | 阶段名称 | 此阶段等待指定阶段完成 |
| Gate: | 否 | Shell命令或描述 | 在下一阶段开始前必须通过 |
| Max-Retries: | 否 | 整数(默认:2) | 升级前的门禁失败重试次数 |
| Shell-Gate: | 否 | true | 允许门禁命令中的Shell元字符(仅用于受信任、已审查的门禁) |
阶段类型
- - impl(默认)——实现工作;代理编写代码、文件、配置
- review——评估性;代理生成结构化的发现报告;如果发现问题则触发自动修复循环
- extract——轻量级解析或总结;路由到Haiku
模型路由
| 别名 | 映射到 | 用途 |
|---|
| haiku | claude-haiku / 最便宜的可用模型 | 提取、解析、结构化输出 |
| sonnet |
claude-sonnet | 实现、研究、多文件工作 |
| gpt | gpt-4o 或等效模型 | 替代实现路径 |
| opus | claude-opus | 判断、审查、最终质量门禁 |
OpenForge将这些别名映射到你的OpenClaw实例中配置的任何模型。如果某个模型别名不可用,则使用Sonnet作为安全的回退。
执行协议
当OpenForge被触发时,遵循以下精确顺序:
步骤1 — 解析PRD
读取PRD文件。提取:
- - 标题和目标
- 所有阶段及其顺序、模型、类型、依赖关系、门禁和任务列表
- 识别哪些阶段是 [parallel] 的,哪些有 depends: 约束
构建依赖图。没有 depends: 且标记为 [parallel] 的阶段可以同时生成。
视野受限分解: 估算所有阶段的总步骤数。如果PRD包含超过40个估算步骤,则将复杂阶段分解为每个不超过20个步骤的子阶段。如果在20-40步之间,则在阶段之间插入一个中间质量检查点。少于20步,直接执行。这可以防止长视野任务上的准确性崩溃(研究:LORE基准测试显示超过120步后准确性趋近于0)。
步骤2 — 预检检查
在生成任何内容之前:
- - 确认PRD至少有一个阶段
- 确认所有 depends: 引用指向真实的阶段
- 确认工作目录存在(如果指定)
- 如果任何检查失败:停止并清晰报告问题
步骤3 — 执行阶段
对于每一波阶段(其所有依赖都已满足的阶段):
如果有多个 [parallel] 阶段: 使用 sessions_spawn 将它们作为子代理同时生成。向每个子代理传递:
- - 完整的PRD上下文
- 其特定的阶段任务
- 要使用的模型
- 门禁命令(如果有)
- 工作目录
如果某个阶段有 depends:: 等待所有指定的阶段完成后再生成。
顺序阶段(没有 [parallel] 标签):按声明顺序一次运行一个。
步骤4 — 门禁评估
每个阶段完成后:
- 1. 如果指定了门禁命令:
-
首先验证门禁命令。 拒绝包含Shell元字符(;、&&、||、|、$(、 、>、<)的命令,除非该阶段包含 Shell-Gate: true。这可以防止因PRD内容导致的意外或恶意的任意Shell执行。
- 使用 exec 运行验证后的门禁命令
- 2. 侵蚀检查(代码阶段): 如果该阶段生成了代码,测量结构复杂度。如果高圈复杂度函数(圈复杂度 > 10)中的圈复杂度质量相比前一阶段的基线增加了超过5%,则在继续之前标记为需要审查或强制进行重构子阶段。这可以防止跨顺序阶段的质量下降(研究:SlopCodeBench显示80%的代理轨迹存在结构侵蚀)。
- 如果门禁通过(退出码0):标记阶段完成,继续
- 如果失败:重试该阶段最多 Max-Retries 次(默认:2),将失败输出作为上下文传递
- 如果重试次数耗尽:升级给Corbin并停止
步骤5 — 审查到修复循环
对于 Type: review 的阶段:
- 1. 审查代理生成结构化的发现报告
- 解析报告以查找阻塞/必需的问题
- 如果存在问题:
- 生成一个