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).
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.A PRD is a markdown file. OpenForge reads it top-to-bottom and extracts phases.
# PRD: My Feature
## Objective
Build a CSV export endpoint for the API.
## Phases
### Phase: scaffold [parallel]
**Model:** sonnet
**Tasks:**
- Create the route handler in `src/routes/export.ts`
- Write the CSV serializer in `src/lib/csv.ts`
**Gate:** `npm run build` must pass
### Phase: test [depends: scaffold]
**Model:** sonnet
**Tasks:**
- Write unit tests for the CSV serializer
- Write integration test for the export endpoint
**Gate:** `npm test` must pass
### Phase: review [depends: test]
**Model:** opus
**Type:** review
**Tasks:**
- Review the full implementation for correctness, edge cases, and security
- Check error handling on malformed input
**Gate:** Review must find zero blocking issues
| Field | Required | Values | Meaning |
|---|---|---|---|
| ------- | ---------- | -------- | --------- |
Model: | No | haiku, sonnet, gpt, opus | Model tier for this phase |
Type: | 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) |
impl (default) — implementation work; agent writes code, files, configsreview — evaluative; agent produces a structured findings report; triggers auto-fix loop if issues foundextract — lightweight parsing or summarization; routed to Haiku| Alias | Maps To | Use For |
|---|---|---|
| ------- | --------- | --------- |
haiku | claude-haiku / cheapest available | Extraction, parsing, structured output |
sonnet | 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.
When OpenForge is triggered, follow this exact sequence:
Read the PRD file. Extract:
[parallel] and which have depends: constraintsBuild 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).
Before spawning anything:
depends: references name real phasesFor 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:
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.
After each phase completes:
;, &&, ||, |, $(, ` `, >, <) unless the phase includes Shell-Gate: true`. This prevents accidental or malicious arbitrary shell execution from PRD content.execMax-Retries times (default: 2), passing the failure output as contextFor phases with Type: review:
Review agent prompt structure:
You are performing a structured code review.
Context:
{phase tasks and objective}
Working directory: {cwd}
Produce a report in this exact format:
## Findings
### Blocking
- [issue description] — [file:line if known]
### Required Changes
- [issue description]
### Suggestions
- [issue description]
### Summary
PASS | FAIL
If PASS: no Blocking or Required Changes items.
If FAIL: at least one Blocking or Required Changes item exists.
Fix agent prompt structure:
You are implementing fixes identified in a code review.
Review findings:
{findings report}
Fix all Blocking and Required Changes items. Do not change anything not listed.
Working directory: {cwd}
When complete, summarize what you changed.
When all phases pass their gates:
.openforge/run-{timestamp}.md in the working directory (if a cwd was specified)When spawning a sub-agent for a phase, include:
You are executing Phase: {phase_name} of an OpenForge PRD run.
## Objective
{PRD objective}
## Your Tasks
{task list}
## Working Directory
{cwd or "not specified — use judgment"}
## Prior Phase Outputs
{summaries from completed phases, if any}
## Gate
After completing your tasks, the following command will be run to validate your work:
{gate command or "none"}
## Constraints
- Only modify files relevant to your tasks
- Do not expose credentials, API keys, or secrets
- Write a brief summary of what you did when complete
## Model
You are running as: {model alias}
Escalate to the human (Corbin / operator) when:
escalate: true explicitlyEscalation message format:
⚠️ OpenForge Escalation
PRD: {title}
Phase: {phase_name}
Reason: {specific failure reason}
What happened:
{summary of attempts}
Gate output (if applicable):
{last gate failure output, truncated to 500 chars}
Recommended next step:
{specific suggestion — fix the gate command, revise the PRD, or manual intervention}
exec in the working directory. Review gate commands before running against production systems. Avoid destructive commands (e.g., rm -rf)..openforge/run-{timestamp}.md) to the working directory. No other writes are made by the orchestrator itself.# PRD: Auth Refactor
## Objective
Replace the custom session cookie system with JWT-based auth.
## Phases
### Phase: research [parallel]
**Model:** haiku
**Type:** extract
**Tasks:**
- Read `src/auth/` and summarize all current auth entry points
- List all routes that call `req.session`
### Phase: design [parallel]
**Model:** opus
**Type:** review
**Tasks:**
- Design the JWT strategy: token structure, expiry policy, refresh approach
- Identify migration risks
### Phase: implement [depends: research, design]
**Model:** sonnet
**Tasks:**
- Implement JWT middleware in `src/auth/jwt.ts`
- Replace session calls in all routes identified in research phase
- Update `src/auth/index.ts` to export new middleware
**Gate:** `npm run build && npm test`
**Max-Retries:** 3
### Phase: security-review [depends: implement]
**Model:** opus
**Type:** review
**Tasks:**
- Review JWT implementation for common vulnerabilities (alg confusion, weak secret, missing expiry check)
- Review token storage and transmission
**Gate:** Review must find zero Blocking issues
In this PRD:
research and design run in parallel (no dependencies, both tagged [parallel])implement waits for both, then runs with Sonnetsecurity-review runs last with Opus, triggers auto-fix loop if issues are foundrm -rf)opus isn't available, Sonnet will be used silently| 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 |
共 1 个版本