ralph-cli¶
Binary entry point and CLI parsing.
Overview¶
ralph-cli is the main binary that:
- Parses command-line arguments
- Routes to appropriate commands
- Handles global options
Commands¶
ralph run¶
Execute the orchestration loop.
pub struct RunCommand {
pub prompt: Option<String>,
pub prompt_file: Option<PathBuf>,
pub max_iterations: Option<usize>,
pub completion_promise: Option<String>,
pub dry_run: bool,
pub no_tui: bool,
pub autonomous: bool,
pub idle_timeout: Option<u64>,
pub record_session: Option<PathBuf>,
pub quiet: bool,
pub continue_: bool,
}
ralph init¶
Initialize configuration file.
pub struct InitCommand {
pub backend: Option<String>,
pub preset: Option<String>,
pub list_presets: bool,
pub force: bool,
}
ralph plan¶
Start PDD planning session.
ralph task¶
Generate code task files.
ralph events¶
View event history.
ralph emit¶
Emit an event.
pub struct EmitCommand {
pub topic: String,
pub payload: Option<String>,
pub json: Option<String>,
}
ralph clean¶
Clean up .agent/ directory.
ralph tools¶
Runtime tools subcommands.
Global Options¶
Implementation¶
Command Dispatch¶
pub async fn run() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Command::Run(cmd) => run_command(cmd, &cli.global).await,
Command::Init(cmd) => init_command(cmd, &cli.global).await,
Command::Plan(cmd) => plan_command(cmd, &cli.global).await,
Command::Task(cmd) => task_command(cmd, &cli.global).await,
Command::Events(cmd) => events_command(cmd, &cli.global).await,
Command::Emit(cmd) => emit_command(cmd, &cli.global).await,
Command::Clean(cmd) => clean_command(cmd, &cli.global).await,
Command::Tools(cmd) => tools_command(cmd, &cli.global).await,
}
}
Error Handling¶
fn main() {
if let Err(e) = ralph_cli::run() {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
Shell Completions¶
Generate shell completions:
pub fn generate_completions(shell: Shell) -> String {
let mut cmd = Cli::command();
let mut buf = Vec::new();
generate(shell, &mut cmd, "ralph", &mut buf);
String::from_utf8(buf).unwrap()
}
Usage:
ralph completions bash > ~/.local/share/bash-completion/completions/ralph
ralph completions zsh > ~/.zfunc/_ralph
ralph completions fish > ~/.config/fish/completions/ralph.fish
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Configuration error |
| 3 | Backend not found |
| 4 | Interrupted |
Example: Adding a New Command¶
- Define command struct:
- Add to command enum:
- Implement handler:
pub async fn my_command(cmd: MyCommand, global: &GlobalOptions) -> Result<()> {
// Implementation
Ok(())
}
- Add to dispatch: