1use clap::Parser;
6
7#[derive(Parser, Debug, Default)]
9pub struct VerbosityShorthand {
10 #[arg(
12 short,
13 long,
14 conflicts_with = "verbosity",
15 help = "Quiet mode (same as -v0)"
16 )]
17 pub quiet: bool,
18
19 #[arg(
21 long,
22 short,
23 conflicts_with = "verbosity",
24 help = "Full output mode, no truncation (same as -v3)"
25 )]
26 pub full: bool,
27}
28
29#[derive(Parser, Debug, Default)]
31pub struct DebugVerbosity {
32 #[arg(
34 long,
35 conflicts_with = "verbosity",
36 help = "Debug mode (same as -v4)",
37 hide = true
38 )]
39 pub debug: bool,
40}
41
42#[derive(Parser, Debug, Default)]
44pub struct QuickPresets {
45 #[arg(
47 long,
48 short = 'Q',
49 help = "Quick mode: 1 dev iteration + 1 review (for rapid prototyping)"
50 )]
51 pub quick: bool,
52
53 #[arg(
55 long,
56 short = 'U',
57 help = "Rapid mode: 2 dev iterations + 1 review (fast but more thorough than quick)"
58 )]
59 pub rapid: bool,
60
61 #[arg(
63 long,
64 short = 'L',
65 help = "Long mode: 15 dev iterations + 10 reviews (for thorough development)"
66 )]
67 pub long: bool,
68}
69
70#[derive(Parser, Debug, Default)]
72pub struct StandardPresets {
73 #[arg(
75 long,
76 short = 'S',
77 help = "Standard mode: 5 dev iterations + 2 reviews (default workflow)"
78 )]
79 pub standard: bool,
80
81 #[arg(
83 long,
84 short = 'T',
85 help = "Thorough mode: 10 dev iterations + 5 reviews (balanced but thorough)"
86 )]
87 pub thorough: bool,
88}
89
90#[derive(Parser, Debug, Default)]
92pub struct UnifiedInitFlags {
93 #[arg(
115 long,
116 conflicts_with_all = ["init_global", "init_config", "init_legacy", "init_prompt"],
117 help = "Smart init: create config or PROMPT.md (infers from current state)",
118 value_name = "TEMPLATE",
119 num_args = 0..=1,
120 default_missing_value = "",
121 )]
124 pub init: Option<String>,
125
126 #[arg(
128 long = "force-overwrite",
129 visible_alias = "overwrite",
130 help = "Overwrite existing PROMPT.md without prompting (use with --init or --init-prompt)",
131 hide = true
132 )]
133 pub force_init: bool,
134
135 #[arg(
137 long,
138 conflicts_with_all = ["init", "init_global", "init_legacy", "init_prompt"],
139 help = "Create ~/.config/ralph-workflow.toml with default settings (recommended)",
140 hide = true
141 )]
142 pub init_config: bool,
143
144 #[arg(
146 long,
147 conflicts_with_all = ["init", "init_config", "init_legacy", "init_prompt"],
148 help = "Create ~/.config/ralph-workflow.toml with default settings (recommended)",
149 hide = true
150 )]
151 pub init_global: bool,
152}
153
154#[derive(Parser, Debug, Default)]
156pub struct LegacyInitFlag {
157 #[arg(
159 long,
160 conflicts_with_all = ["init", "init_global", "init_prompt"],
161 help = "(Legacy) Create .agent/agents.toml with default settings (not recommended)",
162 hide = true
163 )]
164 pub init_legacy: bool,
165}
166
167#[derive(Parser, Debug, Default)]
169pub struct AgentListFlags {
170 #[arg(
172 long,
173 help = "Show all agents from registry and config file",
174 hide = true
175 )]
176 pub list_agents: bool,
177
178 #[arg(
180 long,
181 help = "Show only agents that are installed and available",
182 hide = true
183 )]
184 pub list_available_agents: bool,
185}
186
187#[derive(Parser, Debug, Default)]
189pub struct ProviderListFlag {
190 #[arg(
192 long,
193 help = "Show OpenCode provider types with model prefixes and auth commands",
194 hide = true
195 )]
196 pub list_providers: bool,
197}
198
199#[derive(Parser, Debug, Default)]
201pub struct CompletionFlag {
202 #[arg(
204 long,
205 value_name = "SHELL",
206 value_enum,
207 help = "Generate shell completion script (bash, zsh, fish, elvish, powershell)",
208 hide = true
209 )]
210 pub generate_completion: Option<Shell>,
211}
212
213#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
215pub enum Shell {
216 Bash,
218 Zsh,
220 Fish,
222 Elvish,
224 Pwsh,
226}
227
228#[derive(Parser, Debug, Default)]
230pub struct WorkGuideListFlag {
231 #[arg(
233 long = "list-work-guides",
234 visible_alias = "list-templates",
235 help = "Show all available Work Guides for PROMPT.md"
236 )]
237 pub list_work_guides: bool,
238}
239
240#[derive(Parser, Debug, Default)]
242pub struct TemplateCommands {
243 #[arg(
245 long = "init-system-prompts",
246 alias = "init-templates",
247 help = "Create ~/.config/ralph/templates/ with default Agent Prompts (backend AI behavior configuration, NOT Work Guides for PROMPT.md)",
248 default_missing_value = "false",
249 num_args = 0..=1,
250 require_equals = true,
251 hide = true
252 )]
253 pub init_templates: Option<bool>,
254
255 #[arg(
257 long,
258 requires = "init_templates",
259 help = "Overwrite existing system prompt templates during init (use with caution)",
260 hide = true
261 )]
262 pub force: bool,
263
264 #[arg(
266 long,
267 help = "Validate all Agent Prompt templates for syntax errors",
268 hide = true
269 )]
270 pub validate: bool,
271
272 #[arg(
274 long,
275 value_name = "NAME",
276 help = "Show Agent Prompt template content and metadata",
277 hide = true
278 )]
279 pub show: Option<String>,
280
281 #[arg(
283 long,
284 help = "List all Agent Prompt templates with their variables",
285 hide = true
286 )]
287 pub list: bool,
288
289 #[arg(
291 long,
292 help = "List all Agent Prompt templates including deprecated ones"
293 )]
294 pub list_all: bool,
295
296 #[arg(
298 long,
299 value_name = "NAME",
300 help = "Extract variables from an Agent Prompt template",
301 hide = true
302 )]
303 pub variables: Option<String>,
304
305 #[arg(
307 long,
308 value_name = "NAME",
309 help = "Test render a system prompt template with provided variables",
310 hide = true
311 )]
312 pub render: Option<String>,
313}
314
315impl TemplateCommands {
316 pub const fn init_templates_enabled(&self) -> bool {
318 self.init_templates.is_some()
319 }
320}
321
322#[derive(Parser, Debug, Default)]
324pub struct CommitPlumbingFlags {
325 #[arg(
327 long,
328 help = "Run only the commit message generation phase, then exit",
329 hide = true
330 )]
331 pub generate_commit_msg: bool,
332
333 #[arg(
335 long,
336 help = "Stage all changes and commit using .agent/commit-message.txt",
337 hide = true
338 )]
339 pub apply_commit: bool,
340}
341
342#[derive(Parser, Debug, Default)]
346pub struct CommitDisplayFlags {
347 #[arg(long, help = "Read and display .agent/commit-message.txt", hide = true)]
349 pub show_commit_msg: bool,
350
351 #[arg(
353 long,
354 help = "Reset .agent/start_commit to merge-base with main branch (for incremental diff generation)",
355 hide = true
356 )]
357 pub reset_start_commit: bool,
358
359 #[arg(long, help = "Show current review baseline and start commit state")]
362 pub show_baseline: bool,
363}
364
365#[derive(Parser, Debug, Default)]
367pub struct RecoveryFlags {
368 #[arg(
370 long,
371 help = "Resume from last checkpoint (if one exists from a previous interrupted run)",
372 hide = true
373 )]
374 pub resume: bool,
375
376 #[arg(
378 long,
379 help = "Validate configuration and PROMPT.md without running agents",
380 hide = true
381 )]
382 pub dry_run: bool,
383
384 #[arg(
386 long,
387 short = 'd',
388 help = "Show system info, agent status, and config for troubleshooting"
389 )]
390 pub diagnose: bool,
391
392 #[arg(
394 long = "extended-help",
395 visible_alias = "man",
396 help = "Show extended help with shell completion, all presets, and troubleshooting"
397 )]
398 pub extended_help: bool,
399}
400
401#[derive(Parser, Debug, Default)]
403pub struct RebaseFlags {
404 #[arg(
410 long,
411 help = "Enable automatic rebase to main branch before and after pipeline"
412 )]
413 pub with_rebase: bool,
414
415 #[arg(
417 long,
418 help = "Only rebase to main branch, then exit (no pipeline execution)",
419 hide = true
420 )]
421 pub rebase_only: bool,
422
423 #[arg(
425 long,
426 help = "Skip automatic rebase to main branch before and after pipeline",
427 hide = true
428 )]
429 #[deprecated(
430 since = "0.4.2",
431 note = "Rebase is now disabled by default; use --with-rebase to enable"
432 )]
433 pub skip_rebase: bool,
434}
435
436#[derive(Parser, Debug)]
438#[command(name = "ralph")]
439#[command(about = "PROMPT-driven multi-agent orchestrator for git repos")]
440#[command(
441 long_about = "Ralph orchestrates AI coding agents to implement changes based on PROMPT.md.\n\n\
442 It runs a developer agent for code implementation, then a reviewer agent for\n\
443 quality assurance, automatically staging and committing the final result."
444)]
445#[command(version)]
446#[command(after_help = "GETTING STARTED:\n\
447 ralph --init Smart init (infers what you need)\n\
448 ralph --init <work-guide> Create PROMPT.md from a Work Guide\n\
449 ralph \"fix: my bug\" Run the orchestrator\n\
450\n\
451More help: ralph --extended-help (shell completion, all presets, troubleshooting)")]
452pub struct Args {
455 #[command(flatten)]
457 pub verbosity_shorthand: VerbosityShorthand,
458
459 #[command(flatten)]
461 pub debug_verbosity: DebugVerbosity,
462
463 #[command(flatten)]
465 pub quick_presets: QuickPresets,
466
467 #[command(flatten)]
469 pub standard_presets: StandardPresets,
470
471 #[command(flatten)]
473 pub unified_init: UnifiedInitFlags,
474
475 #[command(flatten)]
477 pub legacy_init: LegacyInitFlag,
478
479 #[command(flatten)]
481 pub agent_list: AgentListFlags,
482
483 #[command(flatten)]
485 pub provider_list: ProviderListFlag,
486
487 #[command(flatten)]
489 pub completion: CompletionFlag,
490
491 #[command(flatten)]
493 pub work_guide_list: WorkGuideListFlag,
494
495 #[command(flatten)]
497 pub template_commands: TemplateCommands,
498
499 #[command(flatten)]
501 pub commit_plumbing: CommitPlumbingFlags,
502
503 #[command(flatten)]
505 pub commit_display: CommitDisplayFlags,
506
507 #[command(flatten)]
509 pub recovery: RecoveryFlags,
510
511 #[command(flatten)]
513 pub rebase_flags: RebaseFlags,
514
515 #[arg(
517 default_value = "chore: apply PROMPT loop + review/fix/review",
518 help = "Commit message for the final commit"
519 )]
520 pub commit_msg: String,
521
522 #[arg(
524 long = "developer-iters",
525 short = 'D',
526 env = "RALPH_DEVELOPER_ITERS",
527 value_name = "N",
528 help = "Number of developer agent iterations",
529 aliases = ["developer-iteration", "dev-iter", "d-iters"]
530 )]
531 pub developer_iters: Option<u32>,
532
533 #[arg(
535 long = "reviewer-reviews",
536 short = 'R',
537 env = "RALPH_REVIEWER_REVIEWS",
538 value_name = "N",
539 help = "Number of review-fix cycles (0=skip review, 1=one cycle, default: 2)",
540 aliases = ["reviewer-count", "reviewer-review"]
541 )]
542 pub reviewer_reviews: Option<u32>,
543
544 #[arg(
546 long,
547 env = "RALPH_PRESET",
548 value_name = "NAME",
549 help = "Use a preset agent combination (default, opencode)",
550 hide = true
551 )]
552 pub preset: Option<super::presets::Preset>,
553
554 #[arg(
556 long,
557 short = 'a',
558 env = "RALPH_DEVELOPER_AGENT",
559 aliases = ["driver-agent", "dev-agent", "developer"],
560 value_name = "AGENT",
561 help = "Developer agent for code implementation (default: first in agent_chain.developer)"
562 )]
563 pub developer_agent: Option<String>,
564
565 #[arg(
567 long,
568 short = 'r',
569 env = "RALPH_REVIEWER_AGENT",
570 aliases = ["rev-agent", "reviewer"],
571 value_name = "AGENT",
572 help = "Reviewer agent for code review (default: first in agent_chain.reviewer)"
573 )]
574 pub reviewer_agent: Option<String>,
575
576 #[arg(
578 long,
579 env = "RALPH_DEVELOPER_MODEL",
580 value_name = "MODEL_FLAG",
581 help = "Model flag for developer agent (e.g., '-m opencode/glm-4.7-free')",
582 hide = true
583 )]
584 pub developer_model: Option<String>,
585
586 #[arg(
588 long,
589 env = "RALPH_REVIEWER_MODEL",
590 value_name = "MODEL_FLAG",
591 help = "Model flag for reviewer agent (e.g., '-m opencode/claude-sonnet-4')",
592 hide = true
593 )]
594 pub reviewer_model: Option<String>,
595
596 #[arg(
601 long,
602 env = "RALPH_DEVELOPER_PROVIDER",
603 value_name = "PROVIDER",
604 help = "Provider for developer agent: 'opencode' (Zen), 'zai'/'zhipuai' (Z.AI direct), 'anthropic'/'openai' (direct API)",
605 hide = true
606 )]
607 pub developer_provider: Option<String>,
608
609 #[arg(
614 long,
615 env = "RALPH_REVIEWER_PROVIDER",
616 value_name = "PROVIDER",
617 help = "Provider for reviewer agent: 'opencode' (Zen), 'zai'/'zhipuai' (Z.AI direct), 'anthropic'/'openai' (direct API)",
618 hide = true
619 )]
620 pub reviewer_provider: Option<String>,
621
622 #[arg(
625 long,
626 env = "RALPH_REVIEWER_JSON_PARSER",
627 value_name = "PARSER",
628 help = "JSON parser for reviewer (claude, codex, gemini, opencode, generic); overrides agent config",
629 hide = true
630 )]
631 pub reviewer_json_parser: Option<String>,
632
633 #[arg(
635 short,
636 long,
637 value_name = "LEVEL",
638 value_parser = clap::value_parser!(u8).range(0..=4),
639 help = "Output verbosity (0=quiet, 1=normal, 2=verbose [default], 3=full, 4=debug); overrides RALPH_VERBOSITY"
640 )]
641 pub verbosity: Option<u8>,
642
643 #[arg(
645 long,
646 help = "Disable isolation mode: keep NOTES.md and ISSUES.md between runs",
647 hide = true
648 )]
649 pub no_isolation: bool,
650
651 #[arg(
653 long,
654 value_name = "LEVEL",
655 help = "Review depth: standard (balanced), comprehensive (thorough), security (OWASP-focused), incremental (changed files only)",
656 hide = true
657 )]
658 pub review_depth: Option<String>,
659
660 #[arg(
662 long,
663 short = 'c',
664 value_name = "PATH",
665 help = "Path to configuration file (default: ~/.config/ralph-workflow.toml)",
666 hide = true
667 )]
668 pub config: Option<std::path::PathBuf>,
669
670 #[arg(
683 long,
684 value_name = "TEMPLATE",
685 help = "Create PROMPT.md from a Work Guide (use --list-work-guides to see options)",
686 hide = true
687 )]
688 pub init_prompt: Option<String>,
689
690 #[arg(
692 long,
693 short = 'i',
694 help = "Interactive mode: prompt to create PROMPT.md from template when missing",
695 hide = true
696 )]
697 pub interactive: bool,
698
699 #[arg(
701 long,
702 env = "RALPH_GIT_USER_NAME",
703 value_name = "NAME",
704 help = "Git user name for commits (overrides config, env, and git config)",
705 hide = true
706 )]
707 pub git_user_name: Option<String>,
708
709 #[arg(
711 long,
712 env = "RALPH_GIT_USER_EMAIL",
713 value_name = "EMAIL",
714 help = "Git user email for commits (overrides config, env, and git config)",
715 hide = true
716 )]
717 pub git_user_email: Option<String>,
718
719 #[arg(
721 long,
722 help = "Display streaming quality metrics (delta stats, repairs, violations) after agent completion",
723 hide = true
724 )]
725 pub show_streaming_metrics: bool,
726}