skills/ralph/SKILL.md
Self-referential loop until task completion with configurable verification reviewer
npx skillsauth add Thomashighbaugh/opencode ralphInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
[RALPH + ULTRAWORK - ITERATION {{ITERATION}}/{{MAX}}]
Your previous attempt did not output the completion promise. Continue working on the task.
<Purpose> Ralph is a PRD-driven persistence loop that keeps working on a task until ALL user stories in prd.json have passes: true and are reviewer-verified. It wraps ultrawork's parallel execution with session persistence, automatic retry on failure, structured story tracking, and mandatory verification before completion. </Purpose><Use_When>
<Do_Not_Use_When>
autopilot insteadplan skill insteadultrawork directly
</Do_Not_Use_When><Why_This_Exists> Complex tasks often fail silently: partial implementations get declared "done", tests get skipped, edge cases get forgotten. Ralph prevents this by:
<PRD_Mode>
By default, ralph operates in PRD mode. A scaffold prd.json is auto-generated when ralph starts if none exists.
Opt-out: If {{PROMPT}} contains --no-prd, skip PRD generation and work in legacy mode (no story tracking, generic verification). Use this for trivial quick fixes.
Deslop opt-out: If {{PROMPT}} contains --no-deslop, skip the mandatory post-review deslop pass entirely. Use this only when the cleanup pass is intentionally out of scope for the run.
Reviewer selection: Pass --critic=architect, --critic=critic, or --critic=codex in the Ralph prompt to choose the completion reviewer for that run. architect remains the default.
Self-verify mode (default): By default, the executor's own verification (running tests, lint, build, typecheck) is SUFFICIENT for story completion — no external @verifier escalation needed unless self-check fails. This saves 1+ API calls per story.
External-verify mode: Pass --external-verify to require a @verifier/@architect review for every story, even those that pass self-verification. Use for security-sensitive, production-deploy, or audit-trail changes.
Self-verify mode (--self-verify): Explicitly forces self-verify behavior. Useful when you want to confirm the mode is active, or when the task is non-critical iteration work.
</PRD_Mode>
<Execution_Policy>
run_in_background: true for long operations (installs, builds, test suites)model parameter explicitly when delegating to agentsdocs/shared/agent-tiers.md before first delegation to select correct agent tiersPick next story: Read prd.json and select the highest-priority story with passes: false. This is your current focus.
Implement the current story:
prd.jsonrun_in_background: trueSelf-verify the current story's acceptance criteria (executor verifies own work):
a. For EACH acceptance criterion in the story, verify it is met with fresh evidence
b. Run relevant checks (test, build, lint, typecheck) and read the output
c. If any criterion is NOT met, continue working -- do NOT mark the story as complete
d. Self-verification pass (default behavior): The executor's own verification (passing tests, clean build, zero lint errors) is SUFFICIENT for story completion. No external @verifier escalation needed unless:
--external-verify was explicitly specified → proceed to Step 7Mark story complete:
a. When ALL acceptance criteria are verified, set passes: true for this story in prd.json
b. Record progress in progress.txt: what was implemented, files changed, learnings for future iterations
c. Add any discovered codebase patterns to progress.txt
Check PRD completion:
a. Read prd.json -- are ALL stories marked passes: true?
b. If NOT all complete, loop back to Step 2 (pick next story)
c. If ALL complete, proceed to Step 7 (architect verification)
Reviewer verification (tiered, escalating, batch-capable):
@verifier or @architect dispatch. A single review pass covering 3 small stories saves 2 API calls vs reviewing each separately.@verifier / GLM-fast — free tier)@verifier first, escalate to @architect on failure)20 files or security/architectural changes: DIRECT tier (
@architect/ Opus — skip verifier)
--critic=critic, use the OpenCode critic agent for the approval pass--critic=codex, run omc ask codex --agent-prompt critic "..." for the approval pass. The Codex critic prompt MUST include:
/cancel) or on rejection (Step 9). Treating an approved verdict as a reporting checkpoint is a polite-stop anti-pattern.7.5 Mandatory Deslop Pass (runs unconditionally after Step 7 approval, unless {{PROMPT}} contains --no-deslop):
ai-slop-cleaner skill via the Skill tool: Skill("ai-slop-cleaner"). Run in standard mode (not --review) on the files changed during the current Ralph session only.@ai-slop-cleaner — that subagent type does not exist and the call will fail with "Agent type not found". If you see that error, retry with the Skill tool — do NOT substitute a similarly-named agent like code-simplifier as a "closest match".7.6 Regression Re-verification:
--no-deslop was explicitly specified).On approval: After Step 7.6 passes (with Step 7.5 completed, or skipped via --no-deslop), run /cancel to cleanly exit and clean up all state files
On rejection: Fix the issues raised, re-verify with the same reviewer, then loop back to check if the story needs to be marked incomplete
</Steps><Tool_Usage>
@verifier for QUICK tier verification (fast/GLM — free tier, use for simple changes)@architect for complex/security/architectural verification (pro-tier — only when needed)@critic when --critic=criticomc ask codex --agent-prompt critic "..." when --critic=codex. Construct the prompt to include: (a) prd.json acceptance criteria, (b) files changed + related files, (c) explicit optimality question: "Is there a meaningfully simpler, faster, or more maintainable approach that achieves the same acceptance criteria?"@verifier, only escalate to @architect if verifier flags issues@architectstate_write / state_read for ralph mode state persistence between iterationsai-slop-cleaner is a skill, invoke via Skill("ai-slop-cleaner"). architect, critic, executor etc. are agents, invoke via @<name>. If you ever get "Agent type ... not found" for an identifier, the item is a skill — retry with the Skill tool. Do NOT substitute a similarly-named agent as a "closest match".
</Tool_Usage>After refinement: acceptanceCriteria: [ "detectNoPrdFlag('ralph --no-prd fix') returns true", "detectNoPrdFlag('ralph fix this') returns false", "stripNoPrdFlag removes --no-prd and trims whitespace", "TypeScript compiles with no errors (npm run build)" ]
Why good: Generic criteria replaced with specific, testable criteria.
</Good>
<Good>
Correct parallel delegation:
@executor(model="haiku", prompt="Add type export for UserConfig") @executor(model="sonnet", prompt="Implement the caching layer for API responses") @executor(model="opus", prompt="Refactor auth module to support OAuth2 flow")
Why good: Three independent tasks fired simultaneously at appropriate tiers.
</Good>
<Good>
Story-by-story verification:
Why good: Each story verified against its own acceptance criteria before marking complete.
</Good>
<Bad>
Claiming completion without PRD verification:
"All the changes look good, the implementation should work correctly. Task complete."
Why bad: Uses "should" and "look good" -- no fresh evidence, no story-by-story verification, no architect review.
</Bad>
<Bad>
Sequential execution of independent tasks:
@executor("Add type export") → wait → @executor("Implement caching") → wait → @executor("Refactor auth")
Why bad: These are independent tasks that should run in parallel, not sequentially.
</Bad>
<Bad>
Keeping generic acceptance criteria:
"prd.json created with criteria: Implementation is complete, Code compiles. Moving on to coding."
Why bad: Did not refine scaffold criteria into task-specific ones. This is PRD theater.
</Bad>
</Examples>
<Escalation_And_Stop_Conditions>
- Stop and report when a fundamental blocker requires user input (missing credentials, unclear requirements, external service down)
- Stop when the user says "stop", "cancel", or "abort" -- run `/cancel`
- Continue working when the hook system sends "The boulder never stops" -- this means the iteration continues
- If the selected reviewer rejects verification, fix the issues and re-verify (do not stop)
- If the same issue recurs across 3+ iterations, report it as a potential fundamental problem
- **Early exit**: If 3 consecutive iterations show no progress (no stories marked complete, no new code), stop and escalate to user
- **Do NOT stop after Step 7 approval.** The boulder continues through 7 → 7.5 → 7.6 → 8 in the same turn as a single chain. Step 7 is a checkpoint inside the loop, not a reporting moment. Treating an architect/critic APPROVED verdict as "time to summarise and wait for user acknowledgment" is a polite-stop anti-pattern — the only reporting moments in Ralph are Step 8 (successful cancel) or Step 9 (rejection).
</Escalation_And_Stop_Conditions>
<Final_Checklist>
- [ ] All prd.json stories have `passes: true` (no incomplete stories)
- [ ] prd.json acceptance criteria are task-specific (not generic boilerplate)
- [ ] All requirements from the original task are met (no scope reduction)
- [ ] Zero pending or in_progress TODO items
- [ ] Fresh test run output shows all tests pass
- [ ] Fresh build output shows success
- [ ] lsp_diagnostics shows 0 errors on affected files
- [ ] progress.txt records implementation details and learnings
- [ ] Selected reviewer verification passed against specific acceptance criteria
- [ ] ai-slop-cleaner pass completed on changed files (or `--no-deslop` specified)
- [ ] Post-deslop regression tests pass
- [ ] `/cancel` run for clean state cleanup
</Final_Checklist>
<Advanced>
## Background Execution Rules
**Run in background** (`run_in_background: true`):
- Package installation (npm install, pip install, cargo build)
- Build processes (make, project build commands)
- Test suites
- Docker operations (docker build, docker pull)
**Run blocking** (foreground):
- Quick status checks (git status, ls, pwd)
- File reads and edits
- Simple commands
</Advanced>
Original task:
{{PROMPT}}
tools
Create valid, type-safe TypeScript tools for OpenCode — generates correct boilerplate, typed interfaces, and handler stubs. Use when building new tools for global config or per-project .opencode/tools/.
testing
Explore multiple solution branches in parallel, evaluate each, and recommend the best path. Use when the user explicitly invokes /ideation tree-of-thoughts or asks for "tree of thought" / "branching exploration".
testing
Run multiple independent reasoning passes and find consensus. Use when the decision is critically important, the stakes are high, or the user explicitly requests "run it multiple times" / "check consistency" / "self-consistency".
testing
Optimization by PROmpting — generate candidate prompt variations, test each against a benchmark, and report the best performer. Use when the user invokes /ideation opro or asks for "prompt optimization" / "OPRO".