$ralplan -> $ralph -> $code-review
If $code-review is not clean, Autopilot returns to $ralplan with the review findings as the next planning input, then continues again through $ralph and $code-review until the review is clean or a hard blocker is reported.
Phase ralplan — consensus planning gate
- Ground the task with pre-context intake.
- Run or resume
$ralplan to produce/update PRD and test-spec artifacts.
- When returning from a non-clean review, include
return_to_ralplan_reason and the review findings as first-class planning input.
- Required handoff artifact: an approved plan/test spec suitable for
$ralph.
Phase ralph — implementation + verification loop
- Run
$ralph from the approved ralplan artifacts.
- Ralph owns implementation, tests, build/lint/typecheck evidence, deslop where applicable, and architect verification.
- Required handoff artifact: implementation evidence and changed-file summary suitable for
$code-review.
Phase code-review — merge-readiness gate
- Run
$code-review on the diff/artifacts produced by $ralph.
- A clean review means final recommendation
APPROVE with architectural status CLEAR.
COMMENT, REQUEST CHANGES, any architectural WATCH/BLOCK, or any unresolved finding is not clean.
- If not clean, increment the review cycle, persist
review_verdict, set return_to_ralplan_reason, and transition back to Phase ralplan.
The only normal terminal state is complete after a clean code review. Cancellation, blocked credentials, unrecoverable repeated failures, or explicit user stop may terminate earlier with preserved state.
Before Phase ralplan starts or resumes:
- Derive a task slug from the request.
- Reuse the latest relevant
.omx/context/{slug}-*.md snapshot when available.
- If none exists, create
.omx/context/{slug}-{timestamp}.md (UTC YYYYMMDDTHHMMSSZ) with:
- task statement
- desired outcome
- known facts/evidence
- constraints
- unknowns/open questions
- likely codebase touchpoints
- If ambiguity remains high, run
explore first for brownfield facts, then run the Socratic $deep-interview --quick <task> before $ralplan.
- Carry the snapshot path in Autopilot state and all handoff artifacts.
</Pre-context Intake>
Required fields:
{
"mode": "autopilot",
"active": true,
"current_phase": "ralplan",
"iteration": 1,
"review_cycle": 0,
"max_iterations": 10,
"phase_cycle": ["ralplan", "ralph", "code-review"],
"handoff_artifacts": {
"context_snapshot_path": ".omx/context/<slug>-<timestamp>.md",
"ralplan": null,
"ralph": null,
"code_review": null
},
"review_verdict": null,
"return_to_ralplan_reason": null
}
- On start:
state_write({mode:"autopilot", active:true, current_phase:"ralplan", iteration:1, review_cycle:0, state:{phase_cycle:["ralplan","ralph","code-review"], handoff_artifacts:{context_snapshot_path, ralplan:null, ralph:null, code_review:null}, review_verdict:null, return_to_ralplan_reason:null}})
- On ralplan -> ralph: set
current_phase:"ralph", persist the plan/test-spec paths under handoff_artifacts.ralplan.
- On ralph -> code-review: set
current_phase:"code-review", persist implementation/test evidence under handoff_artifacts.ralph.
- On clean review: set
active:false, current_phase:"complete", persist review_verdict:{recommendation:"APPROVE", architectural_status:"CLEAR", clean:true} and completed_at.
- On non-clean review: increment
iteration and review_cycle, set current_phase:"ralplan", persist review_verdict:{..., clean:false}, persist handoff_artifacts.code_review, and set return_to_ralplan_reason to a concise review-driven reason.
- On cancellation: run
$cancel; preserve progress for resume rather than deleting handoff artifacts.
Do not restart discovery or discard handoff artifacts on continuation.
ralplan -> ralph -> code-review
Pipeline state should use current_phase values that match the same phase names (ralplan, ralph, code-review, complete, failed) and should carry iteration, review_cycle, handoff_artifacts, review_verdict, and return_to_ralplan_reason alongside stage results.
1---2name: autopilot3description: [OMX] Strict autonomous loop: $ralplan -> $ralph -> $code-review4---56<Purpose>7Autopilot is the strict autonomous delivery loop for non-trivial work. Its primary contract is exactly:89```text10$ralplan -> $ralph -> $code-review11```1213If `$code-review` is not clean, Autopilot returns to `$ralplan` with the review findings as the next planning input, then continues again through `$ralph` and `$code-review` until the review is clean or a hard blocker is reported.14</Purpose>1516<Use_When>17- User wants hands-off execution from a concrete idea, issue, PRD, or requirements artifact to reviewed code18- User says `$autopilot`, "autopilot", "auto pilot", "autonomous", "build me", "create me", "make me", "full auto", "handle it all", or "I want a/an..."19- Task needs planning, implementation, verification, and code review with automatic follow-up when review is not clean20</Use_When>2122<Do_Not_Use_When>23- User wants to explore options or brainstorm -- use `$plan` / `$ralplan`24- User says "just explain", "draft only", or "what would you suggest" -- respond conversationally25- User wants a single focused code change -- use `$ralph` or direct executor work26- User wants only review/critique of existing code -- use `$code-review`27</Do_Not_Use_When>2829<Strict_Loop_Contract>30Autopilot must not run a separate broad expansion/planning/execution/QA/validation lifecycle as its primary behavior. It delegates those concerns to the three canonical workflow phases below:31321. **Phase `ralplan`** — consensus planning gate33 - Ground the task with pre-context intake.34 - Run or resume `$ralplan` to produce/update PRD and test-spec artifacts.35 - When returning from a non-clean review, include `return_to_ralplan_reason` and the review findings as first-class planning input.36 - Required handoff artifact: an approved plan/test spec suitable for `$ralph`.37382. **Phase `ralph`** — implementation + verification loop39 - Run `$ralph` from the approved ralplan artifacts.40 - Ralph owns implementation, tests, build/lint/typecheck evidence, deslop where applicable, and architect verification.41 - Required handoff artifact: implementation evidence and changed-file summary suitable for `$code-review`.42433. **Phase `code-review`** — merge-readiness gate44 - Run `$code-review` on the diff/artifacts produced by `$ralph`.45 - A clean review means final recommendation `APPROVE` with architectural status `CLEAR`.46 - `COMMENT`, `REQUEST CHANGES`, any architectural `WATCH`/`BLOCK`, or any unresolved finding is not clean.47 - If not clean, increment the review cycle, persist `review_verdict`, set `return_to_ralplan_reason`, and transition back to Phase `ralplan`.4849The only normal terminal state is `complete` after a clean code review. Cancellation, blocked credentials, unrecoverable repeated failures, or explicit user stop may terminate earlier with preserved state.50</Strict_Loop_Contract>5152<Pre-context Intake>53Before Phase `ralplan` starts or resumes:541. Derive a task slug from the request.552. Reuse the latest relevant `.omx/context/{slug}-*.md` snapshot when available.563. If none exists, create `.omx/context/{slug}-{timestamp}.md` (UTC `YYYYMMDDTHHMMSSZ`) with:57 - task statement58 - desired outcome59 - known facts/evidence60 - constraints61 - unknowns/open questions62 - likely codebase touchpoints634. If ambiguity remains high, run `explore` first for brownfield facts, then run the Socratic `$deep-interview --quick <task>` before `$ralplan`.645. Carry the snapshot path in Autopilot state and all handoff artifacts.65</Pre-context Intake>6667<Execution_Policy>68- Always execute phases in order: `ralplan`, then `ralph`, then `code-review`.69- Never skip directly from vague/freeform expansion to implementation; unclear input must be clarified or planned through `$ralplan`.70- A non-clean `$code-review` always returns to `$ralplan`; do not patch findings ad hoc outside the loop.71- Each phase must write/update Autopilot state before handing off.72- Use existing hooks, `.omx/state`, `$ralplan`, `$ralph`, `$code-review`, and pipeline primitives; do not invent a separate execution framework.73- Continue automatically through safe reversible phase transitions. Ask only for destructive, credential-gated, or materially preference-dependent branches.74- Apply the shared workflow guidance pattern: outcome-first framing, concise visible updates for multi-step execution, local overrides for the active workflow branch, validation proportional to risk, explicit stop rules, and automatic continuation for safe reversible steps. Ask only for material, destructive, credentialed, external-production, or preference-dependent branches.75</Execution_Policy>7677<State_Management>78Use `omx_state` MCP tools (or `omx state ... --json` fallback if MCP transport is unavailable) for Autopilot lifecycle state. State must be session-aware when a session id exists.7980Required fields:8182```json83{84 "mode": "autopilot",85 "active": true,86 "current_phase": "ralplan",87 "iteration": 1,88 "review_cycle": 0,89 "max_iterations": 10,90 "phase_cycle": ["ralplan", "ralph", "code-review"],91 "handoff_artifacts": {92 "context_snapshot_path": ".omx/context/<slug>-<timestamp>.md",93 "ralplan": null,94 "ralph": null,95 "code_review": null96 },97 "review_verdict": null,98 "return_to_ralplan_reason": null99}100```101102- **On start**: `state_write({mode:"autopilot", active:true, current_phase:"ralplan", iteration:1, review_cycle:0, state:{phase_cycle:["ralplan","ralph","code-review"], handoff_artifacts:{context_snapshot_path, ralplan:null, ralph:null, code_review:null}, review_verdict:null, return_to_ralplan_reason:null}})`103- **On ralplan -> ralph**: set `current_phase:"ralph"`, persist the plan/test-spec paths under `handoff_artifacts.ralplan`.104- **On ralph -> code-review**: set `current_phase:"code-review"`, persist implementation/test evidence under `handoff_artifacts.ralph`.105- **On clean review**: set `active:false`, `current_phase:"complete"`, persist `review_verdict:{recommendation:"APPROVE", architectural_status:"CLEAR", clean:true}` and `completed_at`.106- **On non-clean review**: increment `iteration` and `review_cycle`, set `current_phase:"ralplan"`, persist `review_verdict:{..., clean:false}`, persist `handoff_artifacts.code_review`, and set `return_to_ralplan_reason` to a concise review-driven reason.107- **On cancellation**: run `$cancel`; preserve progress for resume rather than deleting handoff artifacts.108</State_Management>109110<Continuation_And_Resume>111When the user says `continue`, `resume`, or `keep going` while Autopilot is active, read `autopilot-state.json` and continue from `current_phase`:112- `ralplan`: run/update consensus planning from current handoffs and any `return_to_ralplan_reason`.113- `ralph`: execute the approved plan and record verification evidence.114- `code-review`: review the current diff and decide clean vs return-to-ralplan.115- `complete`: report completion evidence; do not restart.116117Do not restart discovery or discard handoff artifacts on continuation.118</Continuation_And_Resume>119120<Pipeline_Orchestrator>121Autopilot may be represented by the configurable pipeline orchestrator (`src/pipeline/`) when useful. The Autopilot pipeline contract is:122123```text124ralplan -> ralph -> code-review125```126127Pipeline state should use `current_phase` values that match the same phase names (`ralplan`, `ralph`, `code-review`, `complete`, `failed`) and should carry `iteration`, `review_cycle`, `handoff_artifacts`, `review_verdict`, and `return_to_ralplan_reason` alongside stage results.128</Pipeline_Orchestrator>129130<Escalation_And_Stop_Conditions>131- Stop and report a blocker when required credentials/authority are missing.132- Stop and report when the same review or verification failure recurs across 3 review cycles with no meaningful new plan.133- Stop when the user says "stop", "cancel", or "abort" and run `$cancel`.134- Otherwise, continue the loop until `$code-review` is clean.135</Escalation_And_Stop_Conditions>136137<Final_Checklist>138- [ ] Phase `ralplan` produced/updated approved planning artifacts139- [ ] Phase `ralph` implemented and verified the plan with fresh evidence140- [ ] Phase `code-review` returned a clean verdict (`APPROVE` + `CLEAR`)141- [ ] `review_verdict.clean` is true and `return_to_ralplan_reason` is null142- [ ] Tests/build/lint/typecheck evidence from Ralph is available in handoff artifacts143- [ ] Autopilot state is marked `complete` or cancellation state is preserved coherently144- [ ] User receives a concise summary with plan, implementation, verification, and review evidence145</Final_Checklist>146147<Examples>148<Good>149User: `$autopilot implement GitHub issue #42`150Flow: create/load context snapshot -> `$ralplan` issue plan -> `$ralph` implementation + tests -> `$code-review`; if review requests changes, return to `$ralplan` with findings.151</Good>152153<Good>154User: `continue`155Context: Autopilot state says `current_phase:"code-review"`.156Flow: run `$code-review` on current diff, persist verdict, finish if clean or transition to `ralplan` with findings if not clean.157</Good>158159<Bad>160Autopilot invents independent "Expansion", "QA", and "Validation" phases and treats them as the primary lifecycle.161Why bad: this bypasses the strict `$ralplan -> $ralph -> $code-review` contract.162</Bad>163</Examples>