Skip to main content

ralph/cli/prompt/
args.rs

1//! Prompt CLI argument definitions.
2//!
3//! Responsibilities:
4//! - Define clap structures and enum routing for `ralph prompt ...`.
5//! - Validate phase parsing for worker prompt previews.
6//!
7//! Not handled here:
8//! - Prompt execution logic.
9//! - Resolved-config based routing decisions.
10//!
11//! Invariants/assumptions:
12//! - Phase parsing accepts only 1, 2, or 3.
13
14use clap::{Args, Subcommand};
15
16use crate::{agent, promptflow};
17
18pub fn parse_phase(input: &str) -> anyhow::Result<promptflow::RunPhase> {
19    match input {
20        "1" => Ok(promptflow::RunPhase::Phase1),
21        "2" => Ok(promptflow::RunPhase::Phase2),
22        "3" => Ok(promptflow::RunPhase::Phase3),
23        _ => anyhow::bail!("invalid phase '{input}', expected 1, 2, or 3"),
24    }
25}
26
27#[derive(Args)]
28#[command(
29    about = "Manage and inspect prompt templates",
30    after_long_help = "Commands to view, export, and sync prompt templates.\n\nPreview compiled prompts (what the agent sees):\n  ralph prompt worker --phase 1 --repo-prompt plan\n  ralph prompt worker --single\n  ralph prompt scan --focus \"risk audit\" --repo-prompt off\n  ralph prompt task-builder --request \"Add tests\"\n\nList and view raw templates:\n  ralph prompt list\n  ralph prompt show worker --raw\n  ralph prompt diff worker\n\nExport and sync templates:\n  ralph prompt export --all\n  ralph prompt export worker\n  ralph prompt sync --dry-run\n  ralph prompt sync --force\n"
31)]
32pub struct PromptArgs {
33    #[command(subcommand)]
34    pub command: PromptCommand,
35}
36
37#[derive(Subcommand)]
38pub enum PromptCommand {
39    Worker(PromptWorkerArgs),
40    Scan(PromptScanArgs),
41    TaskBuilder(PromptTaskBuilderArgs),
42    List,
43    Show(PromptShowArgs),
44    Export(PromptExportArgs),
45    Sync(PromptSyncArgs),
46    Diff(PromptDiffArgs),
47}
48
49#[derive(Args)]
50pub struct PromptWorkerArgs {
51    #[arg(long, conflicts_with = "phase")]
52    pub single: bool,
53    #[arg(long, value_parser = parse_phase)]
54    pub phase: Option<promptflow::RunPhase>,
55    #[arg(long)]
56    pub task_id: Option<String>,
57    #[arg(long)]
58    pub plan_file: Option<std::path::PathBuf>,
59    #[arg(long)]
60    pub plan_text: Option<String>,
61    #[arg(long, default_value_t = 1)]
62    pub iterations: u8,
63    #[arg(long, default_value_t = 1)]
64    pub iteration_index: u8,
65    #[arg(long = "repo-prompt", value_enum, value_name = "MODE")]
66    pub repo_prompt: Option<agent::RepoPromptMode>,
67    #[arg(long)]
68    pub explain: bool,
69}
70
71#[derive(Args)]
72pub struct PromptScanArgs {
73    #[arg(long, default_value = "")]
74    pub focus: String,
75    #[arg(short = 'm', long, value_enum, default_value_t = super::super::scan::ScanMode::Maintenance)]
76    pub mode: super::super::scan::ScanMode,
77    #[arg(long = "repo-prompt", value_enum, value_name = "MODE")]
78    pub repo_prompt: Option<agent::RepoPromptMode>,
79    #[arg(long)]
80    pub explain: bool,
81}
82
83#[derive(Args)]
84pub struct PromptTaskBuilderArgs {
85    #[arg(long)]
86    pub request: Option<String>,
87    #[arg(long, default_value = "")]
88    pub tags: String,
89    #[arg(long, default_value = "")]
90    pub scope: String,
91    #[arg(long = "repo-prompt", value_enum, value_name = "MODE")]
92    pub repo_prompt: Option<agent::RepoPromptMode>,
93    #[arg(long)]
94    pub explain: bool,
95}
96
97#[derive(Args)]
98pub struct PromptShowArgs {
99    pub name: String,
100    #[arg(long)]
101    pub raw: bool,
102}
103
104#[derive(Args)]
105pub struct PromptExportArgs {
106    pub name: Option<String>,
107    #[arg(long)]
108    pub all: bool,
109    #[arg(long)]
110    pub force: bool,
111}
112
113#[derive(Args)]
114pub struct PromptSyncArgs {
115    #[arg(long)]
116    pub dry_run: bool,
117    #[arg(long)]
118    pub force: bool,
119}
120
121#[derive(Args)]
122pub struct PromptDiffArgs {
123    pub name: String,
124}