Ralph
Execute the Ralph Loop (PRD §16) for the task specified below.
# /ralph — Execute Ralph Loop for a Task
Execute the Ralph Loop (PRD §16) for the task specified below.
**Task:** $ARGUMENTS
## Instructions
1. **READ** `tasks/$ARGUMENTS.md` (or search `tasks/` for the matching T-NNNN file).
2. **READ** `PRD.md` sections referenced in the task's `PRD-ref` field.
3. **READ** `.claude/runs/` for any prior state on this task.
4. **WRITE** `.claude/runs/<ISO8601_timestamp>/state.json` with initial plan:
```json
{
"task_id": "<T-NNNN>",
"started_at": "<ISO8601>",
"iteration": 1,
"subtasks": [],
"status": "planning"
}
DECOMPOSE the task into subtasks ≤ 4 hours each. If a subtask is > 4h, split it and update the task file.
ROUTE each subtask to the correct subagent per
AGENTS.mdand PRD §15 routing matrix.VERIFY each subagent's output by running the appropriate §17 DoD gates:
- Gate 1-3: lint, format, types (
npm run lint,ruff check,mypy --strict) - Gate 4-5: unit tests + coverage (
pytest --cov,vitest --coverage) - Gate 6: integration tests (requires compose services running)
- Gate 7: security scan (
bandit,npm audit --audit-level=high,gitleaks detect) - Gate 8-9: RBAC + tenant isolation (if auth/access changed)
- Gate 10: AI eval suite (if
workers/app/prompts/**orworkers/app/ai/**changed) - Gate 11: migration roundtrip (if
cms/migrations/**orinfra/supabase/**changed) - Gate 12:
docker compose build - Gate 13:
playwright test(on final integration)
- Gate 1-3: lint, format, types (
JUDGE: If all gates pass → go to step 9. If any gate fails → go to REPAIR.
REPAIR: Read the exact failure output. Generate a targeted fix prompt. Route back to the original subagent. Increment
iterationcounter. Return to step 7.- HALT if
iteration >= 5OR same gate fails with same root cause ≥ 3 times. - On halt: write
BLOCKED-<T-NNNN>.mdwith full diagnosis and stop.
- HALT if
COMMIT:
- Write conventional commit:
feat(T-NNNN): <title> - Include evidence bundle in PR description: test output snippets, coverage report, eval results.
- Write conventional commit:
REPORT: Append to
.claude/runs/<timestamp>/events.jsonl:
{"iteration": N, "subagent": "...", "action": "...", "gates_passed": [...], "gates_failed": [...], "retry_count": N}
- Mark task as DONE in
tasks/<T-NNNN>.md(check all acceptance criteria).
Maintain Ralph?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Ralph on getagentictools](https://getagentictools.com/loops/franciscocostacarneiro-ralph-execute-ralph-loop-for-a-task?ref=badge) npx agentictools info loops/franciscocostacarneiro-ralph-execute-ralph-loop-for-a-task The second line is the CLI lookup for this page — handy in READMEs and docs.