templates/skills/workflows/ralph/SKILL.md
Autonomous AI agent loop for iterative task implementation (@hivehub/rulebook ralph)
npx skillsauth add hivellm/rulebook Ralph Autonomous LoopInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Purpose: Automate iterative feature implementation using Ralph's autonomous agent loop pattern.
Ralph is installed as part of @hivehub/rulebook:
npm install -g @hivehub/rulebook
# or
npx @hivehub/rulebook init
# Create task specifications in .rulebook/tasks/
rulebook task create my-feature
# Initialize Ralph
rulebook ralph init
# This creates:
# - .rulebook-ralph/prd.json (task specifications in PRD format)
# - .rulebook-ralph/progress.txt (learning log across iterations)
# - .rulebook-ralph/history/ (per-iteration metadata)
# Run with default settings
rulebook ralph run
# Or with custom iterations and tool
rulebook ralph run --max-iterations 10 --tool claude
# Check current status
rulebook ralph status
# View iteration history
rulebook ralph history
# See learnings discovered
rulebook ralph history --learnings
1. Pick highest-priority incomplete task from PRD
2. Execute AI agent (Claude Code, Cursor, or Gemini)
- Provide full PRD context
- Include progress.txt (learnings from past iterations)
- Include git history (recent commits)
3. Run quality gates (type-check, lint, tests)
4. If success:
- Commit changes with iteration metadata
- Update task status to completed
- Record learnings to progress.txt
5. If failure:
- Mark task as blocked
- Record error and blockers to progress.txt
6. Repeat until all tasks completed or max iterations reached
Each iteration starts fresh:
This pattern prevents "context degradation" where AI agent loses track of architectural decisions across many iterations.
{
"ralph": {
"enabled": false,
"maxIterations": 10,
"tool": "claude",
"maxContextLoss": 3
}
}
Options:
enabled: Enable Ralph autonomous loop (default: false)maxIterations: Max iterations before stopping (default: 10)tool: AI CLI tool to use (default: "claude")
"claude" — Claude Code CLI"amp" — Amp CLI (for Cursor)"gemini" — Gemini CLImaxContextLoss: Tolerance for incomplete agent outputs (default: 3){
"tasks": [
{
"id": "task-id",
"title": "Task Title",
"description": "What needs to be done",
"priority": 1,
"status": "pending",
"acceptanceCriteria": [
"Criterion 1",
"Criterion 2"
],
"estimatedComplexity": "medium"
}
]
}
Append-only learning log:
=== Iteration 1 ===
Task: implement-auth
Tool: Claude Code
Result: SUCCESS
Learnings:
- Discovered OAuth token refresh pattern (30-min expiry)
- Gotcha: Tokens expire silently, need header check before retry
- Pattern: Use interceptor middleware for transparent refresh
=== Iteration 2 ===
Task: add-caching
Tool: Claude Code
Result: FAILED - Tests failed
Error: Cache invalidation not handling concurrent updates
Blockers: Need to implement distributed cache locking
Break large features into tasks:
# Create tasks for phases
rulebook task create setup-database
rulebook task create create-api-endpoints
rulebook task create add-authentication
rulebook task create write-tests
# Initialize Ralph
rulebook ralph init
# Run autonomous loop — implements all tasks iteratively
rulebook ralph run --max-iterations 20
Ralph learns from past iterations:
Stop loop gracefully and resume later:
# Start autonomous loop
rulebook ralph run --max-iterations 100
# (User presses Ctrl+C)
# Loop pauses, state saved
# Resume later
rulebook ralph resume
# Continues from last incomplete task with full history
Ralph enforces quality checks after each iteration:
# After each implementation, Ralph runs:
npm run type-check # TypeScript compilation
npm run lint # ESLint (0 warnings)
npm run test # All tests (100% pass)
npm run test:coverage # Coverage threshold met (95%)
If ANY gate fails:
blocked with error details--strict mode)Use Ralph via Model Context Protocol:
// Initialize Ralph
rulebook_ralph_init({ force: false })
→ Returns: { success: true, taskCount: 5, prdPath: "..." }
// Start autonomous loop
rulebook_ralph_run({ maxIterations: 10, tool: "claude" })
→ Returns: { success: true, loopId: "loop-123", status: "running" }
// Query loop status
rulebook_ralph_status()
→ Returns: { loopStatus: "running", iteration: 5, currentTask: "task-id", ... }
// Get iteration history
rulebook_ralph_get_iteration_history({ limit: 10 })
→ Returns: { iterations: [...], total: 12 }
Problem: Ralph stops before reaching max iterations
Cause: All tasks completed (success!) or multiple blockers
Solution: Check rulebook ralph history for blockers
Problem: Task marked blocked multiple times Cause: Task too large, acceptance criteria unclear, or AI context insufficient Solution:
Problem: Type-check, lint, or tests fail after implementation Cause: AI-generated code doesn't meet project standards Solution:
rulebook task create <task-id> (multiple times)rulebook ralph initrulebook ralph run --max-iterations Nrulebook ralph status and rulebook ralph historyRULEBOOK.md in AGENTS.mdrulebook --helprulebook-mcp (stdio transport)research
Author a rulebook task spec interactively — research, draft, ask the user clarifying questions, confirm, then create the tasks in rulebook ready for /rulebook-driver. Use when the user wants to plan/spec a feature before implementing.
development
Behavioral guidelines to reduce common LLM coding mistakes — overcomplication, sloppy refactors, hidden assumptions, weak goals. Use when writing, reviewing, or refactoring code. Auto-applies; invoke explicitly via /karpathy-guidelines or 'follow karpathy discipline'.
data-ai
Use SQL Server for enterprise relational data storage with advanced features, high availability, and Windows integration.
development
Use SQLite for embedded databases, local storage, development, and small-scale applications with zero configuration.