AgentSkillsCN

ralph-wiggum-loop

WHAT:利用持久化迭代循环,自主执行多步骤任务直至完成。WHEN:当用户说“运行 Ralph 循环”、“自主任务”、“完成工作流”、“多步骤任务”时触发。触发条件:复杂工作流、批量处理、无人值守运行、夜间任务。

SKILL.md
--- frontmatter
name: ralph-wiggum-loop
description: "WHAT: Execute autonomous multi-step tasks until completion using persistent iteration loop. WHEN: User says 'run ralph loop', 'autonomous task', 'complete workflow', 'multi-step task'. Trigger on: complex workflows, batch processing, unattended execution, overnight tasks."

Ralph Wiggum Loop - Autonomous Task Executor

When to Use

  • Executing multi-step tasks autonomously (5+ steps)
  • Running unattended batch operations
  • Processing task queues to completion
  • Overnight workflow execution
  • Any task requiring persistence until completion

How It Works

  1. Creates state file with task prompt
  2. Claude works on the task
  3. Claude attempts to exit
  4. Stop hook checks: Is task complete (file in Done/ or promise output)?
  5. YES → Allow exit (success)
  6. NO → Block exit, re-inject prompt, continue
  7. Repeat until complete or max iterations reached

Instructions

  1. Start Ralph Loop (promise-based completion):

    bash
    python3 .claude/skills/ralph-wiggum-loop/scripts/main_operation.py --action start \
      --prompt "Process all files in Needs_Action/, move to Done/ when complete" \
      --completion-promise "TASK_COMPLETE" \
      --max-iterations 10
    
  2. Start Ralph Loop (file-movement completion):

    bash
    python3 .claude/skills/ralph-wiggum-loop/scripts/main_operation.py --action start \
      --prompt "Process invoice request and send email" \
      --watch-file "Needs_Action/INVOICE_client_a.md" \
      --done-folder "Done/" \
      --max-iterations 10
    
  3. Check Loop Status:

    bash
    python3 .claude/skills/ralph-wiggum-loop/scripts/main_operation.py --action status
    
  4. Stop Active Loop:

    bash
    python3 .claude/skills/ralph-wiggum-loop/scripts/main_operation.py --action stop --loop-id LOOP_ID
    
  5. View Loop History:

    bash
    python3 .claude/skills/ralph-wiggum-loop/scripts/main_operation.py --action history --limit 10
    

Completion Strategies

Promise-Based (Simple)

Claude outputs <promise>TASK_COMPLETE</promise> when done.

  • Faster setup
  • Relies on Claude's judgment

File-Movement (Robust)

Stop hook detects when task file moves to Done/.

  • More reliable
  • Natural part of existing workflow
  • Recommended for production

Configuration Options

OptionDefaultDescription
--max-iterations10Maximum loop cycles
--timeout3600Max seconds per iteration
--pause-on-approvaltruePause when HITL needed
--auto-resumetrueResume after approval
--log-iterationstrueLog each iteration

State Files

  • AI_Employee_Vault/Ralph_State/ - Active loop state
  • AI_Employee_Vault/Ralph_History/ - Completed loop logs

Safety Features

  • Maximum iteration limit prevents infinite loops
  • Timeout per iteration prevents hangs
  • Automatic HITL pause for sensitive actions
  • Detailed logging for debugging
  • Human review request on max iterations

Validation

  • State file created
  • Iterations logged
  • Completion detected correctly
  • HITL pause working
  • Max iterations respected

See REFERENCE.md for stop hook implementation.