Ralph wiggum loop

From NaveedTechLab/skills-library · View interactive version

Ralph wiggum loop is an AI agent skill from the GitHub repository NaveedTechLab/skills-library. Implement autonomous task completion loops that persist until tasks are fully finished. Use when running long-running background tasks that must complete without human re-prompting.

How to use this skill

Skill file

Ralph Wiggum Loop

Description

The Ralph Wiggum Loop is an autonomous task completion system that ensures Claude Code persists until tasks are fully completed. Named after the Simpsons character known for his persistence, this system tracks task state and re-injects continuation prompts when Claude attempts to exit before task completion.

Purpose

This skill implements the "autonomous task loop" pattern required for Platinum tier Personal AI Employee certification. It ensures that long-running tasks are completed to specification without human intervention, while maintaining safety limits and audit trails.

Key Features

Task Persistence

Completion Detection

Safety Controls

Vault Integration

Uses the standard vault folder structure:

Configuration

Default Configuration

{
  "ralph_wiggum": {
    "max_global_iterations": 10,
    "max_task_iterations": 5,
    "check_interval_seconds": 5,
    "completion_markers": ["status: completed", "## Completed"],
    "done_folder": "/vault/Done/",
    "failed_folder": "/vault/Failed/",
    "enable_audit_logging": true,
    "emergency_stop_file": ".ralph_stop"
  }
}

How It Works

1. Task registered → tracked in SQLite with unique ID
2. Claude Code works on task
3. Claude Code tries to exit
4. Stop hook intercepts:
   - Check: Is task file in /Done folder?
   - YES → Allow exit, mark task complete
   - NO → Re-inject continuation prompt
5. Repeat until:
   - Task marked complete (file in /Done), OR
   - max_iterations reached (move to /Failed), OR
   - Emergency stop triggered

Usage Scenarios

Register a Task

from ralph_wiggum import RalphWiggumLoop

loop = RalphWiggumLoop()

# Register a new task for tracking
task_id = loop.register_task(
    name="Process monthly invoices",
    source_file="/vault/Needs_Action/invoices-2024-01.md",
    completion_criteria={
        "type": "file_moved",
        "destination": "/vault/Done/"
    }
)

Check Task Completion

# Called by stop hook
is_complete = loop.check_task_completion(task_id)

if not is_complete:
    # Get continuation prompt
    prompt = loop.get_continuation_prompt(task_id)
    # Inject prompt for continued processing

Force Task Completion

# For emergency situations or manual override
loop.force_complete_task(task_id, reason="Manual override by admin")

Integration Points

With Vault System

With Audit Logger

With Safety Enforcer

Security Considerations

Performance Considerations

Dependencies

When NOT to Use This Skill

Common Mistakes

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.