ralph
AGENTS.md19 starsChanged 9 months agoMITView on GitHub
Ralph is a CLI tool for long-running PRD-driven development with AI coding agents (Cursor, Claude Code, or Codex). It orchestrates AI agent sessions that work through tasks defined in a PRD (Product Requirements Document) file, with features like automatic retries, task decomposition, verification, and session memory. These commands manage PRD tasks and progress: The orchestrator is now a service composed of several specialized managers: Services are bootstrapped at startup via src/lib/services/bootstrap.ts and accessed through src/lib/services/container.ts:
The file
Files
Rules for agents
This file provides guidance to coding agents working with code in this repository.
Project Overview
Ralph is a CLI tool for long-running PRD-driven development with AI coding agents (Cursor, Claude Code, or Codex). It orchestrates AI agent sessions that work through tasks defined in a PRD (Product Requirements Document) file, with features like automatic retries, task decomposition, verification, and session memory.
Commands
# Development
bun run dev # Run the CLI directly
bun run src/index.tsx # Alternative: run entry point
# Quality checks (run after changes)
bun run check # Format + lint + fix (oxfmt + oxlint)
bun run typecheck # TypeScript type checking
# Testing
bun test # Run all tests
bun test src/__tests__/lib/config.test.ts # Run single test file
bun test --watch # Watch mode
# Build
bun run build # Production build via scripts/build.tsRalph CLI Commands
These commands manage PRD tasks and progress:
ralph task list # List all tasks with completion status
ralph task current # Show the next pending task
ralph task done <n> # Mark task as complete (by number or title)
ralph task undone <n> # Mark task as not done
ralph progress add "<text>" # Add a progress note
ralph progress show # Display progress notesArchitecture
Entry Point & CLI Flow
src/index.tsx- Main entry, parses args, routes to commands or renders Ink componentssrc/cli/parser.ts- Argument parsing for all CLI commandssrc/cli/commands/- Individual command handlers (status, config, guardrails, etc.)
Core Orchestration
The orchestrator is now a service composed of several specialized managers:
src/lib/services/orchestrator/- Composition root that coordinates all orchestration servicessrc/lib/services/session-manager/- Manages session lifecycle (start, resume, fatal errors)src/lib/services/iteration-coordinator/- Sets up iteration callbacks, manages retry contextssrc/lib/services/handler-coordinator/- Coordinates handlers for verification, decomposition, learningsrc/lib/services/parallel-execution-manager/- Manages parallel task executionsrc/lib/services/branch-mode-manager/- Manages branch-per-task workflow
State Management (Zustand Stores)
src/stores/agentStore.ts- Agent execution state, spawnsAgentRunnersrc/stores/appStore.ts- Application state (PRD, session, current view)src/stores/iterationStore.ts- Tracks iteration progress and timingsrc/stores/agentStatusStore.ts- Agent status display state
Agent Execution
src/lib/agent.ts-AgentRunnerclass handles spawning the agent process (Cursor CLI), streaming output, timeout/stuck detection, retry logic with context injectionsrc/lib/agent-stream.ts- Parses JSON streaming output from Cursor CLIsrc/lib/services/AgentProcessManager.ts- Singleton managing the active agent subprocess
Service Layer (Dependency Injection)
Services are bootstrapped at startup via src/lib/services/bootstrap.ts and accessed through src/lib/services/container.ts:
ProjectRegistryService- Multi-project support, path resolution, stores data in~/.ralph/projects/ConfigService- Layered config (global + project-level)PrdService- PRD file loading/parsingGuardrailsService- Prompt guardrails managementSessionService- Session persistenceSessionMemoryService- Cross-session learning/memoryUsageStatisticsService- Usage tracking and statisticsGitBranchService- Git branch operationsGitProviderService- GitHub integration
Event Communication
src/lib/events.ts- Minimal event bus with onlyagent:completeandagent:errorevents- HandlerCoordinator subscribes to these events for verification, decomposition, learning
- Most communication uses direct callback patterns rather than events
UI Layer (Ink/React)
src/components/RunApp.tsx- Main runtime UIsrc/components/ViewRouter.tsx- Routes between different viewssrc/components/views/- Individual view components
Key Patterns
Path Aliases
import { something } from "@/lib/something.ts"; // src/lib/something.ts
import { Component } from "@/components/index.ts";Service Access
import { getConfigService, getPrdService, getOrchestrator } from "@/lib/services/index.ts";
const config = getConfigService().get();
const orchestrator = getOrchestrator();Testing Services
import { bootstrapTestServices, teardownTestServices } from "@/lib/services/bootstrap.ts";
beforeEach(() => bootstrapTestServices({ config: { get: () => mockConfig } }));
afterEach(() => teardownTestServices());Project Storage Structure
~/.ralph/ # Global Ralph directory
├── config.json # Global config
├── registry.json # Project registry
├── usage-statistics.json # Global usage statistics
└── projects/ # Per-project storage
└── <project-folder>/ # Named by git remote or path
├── config.json # Project-specific config
├── prd.json # PRD file (JSON format)
├── session.json # Active session state
├── session-memory.json
├── guardrails.json
├── instructions.md # Custom agent instructions
└── logs/ # Iteration logsType System
- Types are exported from
src/types.ts(re-exports fromsrc/types/) - Service types defined alongside implementations in
src/lib/services/*/types.ts
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

