agentleFS
nitodeconitodeco/ralph/AGENTS.md

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:

  • In this repository2 other files it gives its agents.

The file

Files
AGENTS.md

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.ts

Ralph 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 notes

Architecture

Entry Point & CLI Flow

  • src/index.tsx - Main entry, parses args, routes to commands or renders Ink components
  • src/cli/parser.ts - Argument parsing for all CLI commands
  • src/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 services
  • src/lib/services/session-manager/ - Manages session lifecycle (start, resume, fatal errors)
  • src/lib/services/iteration-coordinator/ - Sets up iteration callbacks, manages retry contexts
  • src/lib/services/handler-coordinator/ - Coordinates handlers for verification, decomposition, learning
  • src/lib/services/parallel-execution-manager/ - Manages parallel task execution
  • src/lib/services/branch-mode-manager/ - Manages branch-per-task workflow

State Management (Zustand Stores)

  • src/stores/agentStore.ts - Agent execution state, spawns AgentRunner
  • src/stores/appStore.ts - Application state (PRD, session, current view)
  • src/stores/iterationStore.ts - Tracks iteration progress and timing
  • src/stores/agentStatusStore.ts - Agent status display state

Agent Execution

  • src/lib/agent.ts - AgentRunner class handles spawning the agent process (Cursor CLI), streaming output, timeout/stuck detection, retry logic with context injection
  • src/lib/agent-stream.ts - Parses JSON streaming output from Cursor CLI
  • src/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/parsing
  • GuardrailsService - Prompt guardrails management
  • SessionService - Session persistence
  • SessionMemoryService - Cross-session learning/memory
  • UsageStatisticsService - Usage tracking and statistics
  • GitBranchService - Git branch operations
  • GitProviderService - GitHub integration

Event Communication

  • src/lib/events.ts - Minimal event bus with only agent:complete and agent:error events
  • 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 UI
  • src/components/ViewRouter.tsx - Routes between different views
  • src/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 logs

Type System

  • Types are exported from src/types.ts (re-exports from src/types/)
  • Service types defined alongside implementations in src/lib/services/*/types.ts

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.