Skip to content

Exit Conditions

Exit conditions tell ralph when the job is done. Without them, ralph would loop forever.

ralph checks for exit conditions after each iteration:

Diagram

ralph exits for one of these reasons:

The AI outputs the completion marker <promise>COMPLETE</promise>. This is the success case—the task is done.

Reached the maxIterations limit from config. This is a safety net to prevent runaway loops.

The AI process exited with a non-zero code.

User interrupted with Ctrl+C.

ralph detects task completion when the AI outputs:

<promise>COMPLETE</promise>

Include this in your prompt instructions:

## Completion
When all tests pass, output:
<promise>COMPLETE</promise>

Always configure a reasonable maxIterations in .ralph/config.toml:

maxIterations = 20

This prevents:

  • Runaway API costs
  • Infinite loops when the AI can’t complete the task
  • Wasted time on impossible tasks
Task TypeSuggested Limit
Simple fixes5-10
Test coverage15-30
Large refactors30-50
Complex migrations50-100

Start conservative and increase if needed.

Tell the AI exactly when to signal completion:

## Completion
When `npm test` passes AND coverage is above 80%, output:
<promise>COMPLETE</promise>

Help the AI track what’s done:

## Progress
1. Check progress.txt for completed items
2. Update progress.txt after each task
3. When all items are done, output the completion marker

Tell the AI how to verify success:

## Verification
Before signaling completion:
1. Run `npm test` - all tests pass
2. Run `npm run lint` - no errors
3. Run `npm run build` - builds successfully
# Task: Add Test Coverage
Add tests for all untested functions in src/utils/.
## Check Progress
- Run `npm test -- --coverage` to see coverage
- Check progress.txt for completed files
## Guidelines
- One test file per module
- Test success and error paths
- Mock external dependencies
## Completion
When coverage for src/utils/ is 80%+, output:
<promise>COMPLETE</promise>
# Task: Migrate from lodash to native
Replace lodash functions with native equivalents.
## Find work
`grep -r "import.*lodash" src/`
## Migration
- `_.map()``Array.map()`
- `_.filter()``Array.filter()`
- `_.get()` → optional chaining
## Completion
When no lodash imports remain, output:
<promise>COMPLETE</promise>
# Task: Fix Failing Tests
Fix all failing tests.
## Process
1. Run `npm test` to see failures
2. Fix one test at a time
3. Commit after each fix
## Completion
When `npm test` exits with code 0, output:
<promise>COMPLETE</promise>