opencode
opencode copied to clipboard
feat: add ralph-loop for autonomous task completion
Closes #9199
Summary
Add Ralph Loop - a plugin-based mechanism that enables OpenCode to autonomously continue working on tasks without requiring human input after the initial prompt.
This feature is inspired by Ralph and allows the model to iterate on tasks until a completion condition is met or safety limits are reached.
How it works
- User starts a loop with
/ralph-loop "your task" -p "COMPLETION_TEXT" - The model works on the task
- When the model finishes, the
chat.waitinghook fires - If the model's response contains
<promise>COMPLETION_TEXT</promise>, the loop stops - Otherwise, the prompt is re-injected and the model continues
- Loop also stops when max iterations reached (default 20, max 100)
Usage
# Start a loop with completion promise
/ralph-loop -p "I_AM_DONE" Read the TODO file and complete all tasks
# Start with custom iteration limit
/ralph-loop -m 10 -p "FINISHED" Review and fix all linting errors
# Cancel an active loop
/ralph-loop:cancel
Features
-
Completion detection: Model signals completion with
<promise>TEXT</promise>tags - Safety limits: Default 20 iterations, configurable up to 100 max
-
Cancel support:
/ralph-loop:cancelor command palette - Server-side state: Loop persists across UI refreshes
- TUI integration: Command palette entries for start/cancel
Test plan
- [x] Unit tests for state management and arg parsing (21 tests)
- [x] Integration tests for hook flow (17 tests)
- [x] Manual testing: loop starts, iterates, and stops on completion promise
- [x] Manual testing: cancel command stops active loop
- [x] Typecheck passes