smith-ralph

Ralph Loop integration patterns for iterative AI development. Use when starting Ralph loops, managing iterations, or recovering from context compaction. Covers TDD, debugging, context management, and memory persistence.

📖 中文导读:Ralph Loop integration patterns for iterative AI development. Use when starting Ralph loops, managing iterations, or recovering from context compaction. Covers TDD, debugging, context management, and memory persistence. 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: smith-ralph description: Ralph Loop integration patterns for iterative AI development. Use when starting Ralph loops, managing iterations, or recovering from context compaction. Covers TDD, debugging, context management, and memory persistence.

Ralph Loop Integration

  • Load if: Starting /ralph-loop, managing iterations, recovering from compaction
  • Prerequisites: @smith-ctx/SKILL.md, @smith-git/SKILL.md, @smith-serena/SKILL.md

CRITICAL: Ralph Fundamentals (Primacy Zone)

Ralph = iterative prompt loop: Same prompt fed repeatedly, Claude sees previous work in files.

Essential patterns:

  1. Clear completion criteria with <promise> tag
  2. --max-iterations as safety limit (always set)
  3. Atomic commits mark iteration boundaries
  4. Serena memory persists state across compaction

Skills Integration

TDD Workflow (smith-tests)

Pattern: test → implement → run pytest → iterate until <promise>TESTS PASS</promise>.

Each test file = iteration boundary. Commit after green.

Debugging Workflow (smith-validation)

Pattern: hypothesis → test → eliminate → iterate until <promise>ROOT CAUSE FOUND</promise>.

  • Strong Inference: Each hypothesis test = one iteration
  • 5 Whys: Each "Why?" deepening = one iteration
  • Delta Debugging: Split → test → recurse

Task Decomposition (smith-dev)

Pattern: Phase milestones = iteration boundaries. Quality gates between.

Phase 1: [milestone] + tests
Phase 2: [milestone] + tests
Output <promise>COMPLETE</promise> after all phases.

Exploration Workflow (smith-guidance)

Ralph = structured exploration: Read files → Form hypothesis → Design test → Execute → Loop.

Context Management

Ralph burns context rapidly. ~1-3.5k tokens per iteration.

Compaction strategy:

  • At 60%: Prepare retention criteria, continue
  • At 70%: /compact, persist Ralph state to Serena memory
  • After compaction: read_memory() to resume

Essential retention:

  • Iteration number
  • Hypotheses tested/remaining
  • Test results summary
  • File:line references

Commit Strategy

Atomic commits mark iteration boundaries.

  1. Complete iteration (test passes or hypothesis proven)
  2. Commit with iteration number: fix(feature): iteration 3 - resolved null check
  3. If regression, use git bisect to find breaking iteration

Memory Persistence

Serena memories persist Ralph state across compaction.

Memory fields: ralph_[task]_state

  • iteration, hypotheses (tested/remaining), test_results, next_action

Sync timing:

  • After each iteration: write_memory()
  • Before/after compaction: write_memory() / read_memory()
  • @smith-tests/SKILL.md - TDD workflow
  • @smith-validation/SKILL.md - Debugging techniques
  • @smith-dev/SKILL.md - Task decomposition
  • @smith-guidance/SKILL.md - Exploration workflow
  • @smith-ctx/SKILL.md - Context management
  • @smith-git/SKILL.md - Commit patterns
  • @smith-serena/SKILL.md - Memory persistence

ACTION (Recency Zone)

Starting Ralph:

/ralph-loop "[task]" --completion-promise "[DONE]" --max-iterations 20

During iterations:

  1. Read files before changes
  2. Form ONE testable hypothesis
  3. Execute and record result
  4. Commit if progress made
  5. write_memory() after each iteration

On compaction:

  1. write_memory() with full state
  2. After /compact: read_memory() to resume