Skip to main content

Crate ralph_workflow

Crate ralph_workflow 

Source
Expand description

Ralph workflow library for AI agent orchestration.

This crate provides the core functionality for the ralph CLI binary, implementing a reducer-based architecture for orchestrating AI coding agents through development and review cycles.

§Quick Start

Ralph is primarily a CLI binary. For library use (integration testing):

[dev-dependencies]
ralph-workflow = { version = "0.6", features = ["test-utils"] }

§Architecture

Ralph uses an event-sourced reducer architecture. The core state machine follows the pattern:

State → Orchestrator → Effect → Handler → Event → Reducer → State
ComponentPure?Role
reducer::PipelineStateYesImmutable progress snapshot, doubles as checkpoint
reducer::reduceYes(State, Event) → State
reducer::determine_next_effectYesState → Effect
reducer::EffectHandlerNoExecutes effects, produces events

Business logic lives in reducers (pure). I/O lives in handlers (impure).

§Two Effect Layers

Ralph has two distinct effect types for different pipeline stages:

LayerModuleWhenFilesystem Access
AppEffectappBefore repo root knownstd::fs directly
EffectreducerAfter repo root knownVia workspace::Workspace

These layers must never mix: AppEffect cannot use Workspace, and Effect cannot use std::fs directly.

§I/O Abstractions

All I/O is abstracted through traits for testability:

§Feature Flags

  • monitoring (default) - Enable streaming metrics and debugging APIs
  • test-utils - Enable test utilities (MockProcessExecutor, MemoryWorkspace, etc.)
  • hardened-resume (default) - Enable checkpoint file state capture for recovery

§Key Modules

Core Architecture:

  • reducer - Core state machine with pure reducers and effect handlers
  • app - CLI layer operating before repo root is known (AppEffect)
  • phases - Pipeline phase implementations (planning, development, review, commit)

I/O Abstractions:

  • workspace - Filesystem abstraction (WorkspaceFs production, MemoryWorkspace testing)
  • executor - Process execution abstraction for agent spawning

Agent Infrastructure:

  • agents - Agent configuration, registry, and CCS (Claude Code Switch) support
  • json_parser - NDJSON streaming parsers for Claude, Codex, Gemini, OpenCode
  • prompts - Template system for agent prompts

Supporting:

  • git_helpers - Git operations using libgit2 (no CLI dependency)
  • checkpoint - Pipeline state persistence for --resume support
  • config - Configuration loading and verbosity levels

§Error Handling

Most functions return anyhow::Result for flexible error handling with context. Use .context() to add context to errors as they propagate.

Re-exports§

pub use files::llm_output_extraction::extract_development_result_xml;
pub use files::llm_output_extraction::extract_fix_result_xml;
pub use files::llm_output_extraction::extract_issues_xml;
pub use files::llm_output_extraction::validate_continuation_development_result_xml;
pub use files::llm_output_extraction::validate_development_result_xml;
pub use files::llm_output_extraction::validate_fix_result_xml;
pub use files::llm_output_extraction::validate_issues_xml;
pub use files::llm_output_extraction::validate_plan_xml;
pub use files::llm_output_extraction::validate_xml_against_xsd;
pub use workspace::Workspace;

Modules§

agents
Agent Abstraction Module
app
Application entrypoint and pipeline orchestration.
banner
Banner and UI output utilities.
benchmarks
Performance benchmarks for memory profiling
boundary
Boundary composition module.
checkpoint
Pipeline checkpoint system for resume functionality.
cli
CLI argument parsing and command-line interface definitions.
cloud
Cloud integration for containerized deployments.
common
Common utility functions shared across the crate.
config
Configuration Module
config_loading
Configuration loading composition functions.
diagnostics
System and agent diagnostics.
executor
Process execution abstraction for dependency injection.
exit_pause
files
File management utilities for Ralph’s agent files.
git_helpers
Git Helper Functions
guidelines
Language-Specific Review Guidelines Module
interrupt
Interrupt signal handling for graceful checkpoint save.
io
I/O boundary module.
json_parser
JSON Stream Parsing Module
language_detector
Language and Stack Detection Module
logger
Logging and progress display utilities.
logging
Per-run logging infrastructure.
monitoring
Production monitoring and metrics.
phases
Pipeline Phase Orchestration Module
pipeline
Pipeline Execution Module
platform
Platform detection and installation guidance
prompts
Prompt Templates Module
reducer
Reducer-based pipeline architecture.
rendering
Rendering subsystem for user-facing display output.
review_metrics
Review Quality Metrics Module
runtime
Runtime boundary module.
templates
Prompt template management module.
workspace
Workspace filesystem abstraction for explicit path resolution.

Macros§

assert_template_exists
Macro to verify a template file exists and contains expected content.
assert_template_has_variable
include_template
Macro to verify that a string comes from a template file.

Structs§

AgentChildHandle
Result of spawning an agent process.
AgentCommandResult
Result of an agent command execution (for testing).
AgentSpawnConfig
Configuration for spawning an agent process with streaming support.
ChildProcessInfo
Information about child processes of a given parent.
ProcessOutput
Output from an executed process.
RealAgentChild
Wrapper for real std::process::Child.
RealProcessExecutor
Real process executor that uses std::process::Command.

Traits§

AgentChild
Trait for interacting with a spawned agent child process.
ProcessExecutor
Trait for executing external processes.