opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add ralph-loop for autonomous task completion

Open ktsaou opened this issue 15 hours ago • 2 comments

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

  1. User starts a loop with /ralph-loop "your task" -p "COMPLETION_TEXT"
  2. The model works on the task
  3. When the model finishes, the chat.waiting hook fires
  4. If the model's response contains <promise>COMPLETION_TEXT</promise>, the loop stops
  5. Otherwise, the prompt is re-injected and the model continues
  6. 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:cancel or 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

ktsaou avatar Jan 18 '26 23:01 ktsaou