Skip to main content

ralph/cli/machine/
args.rs

1//! Clap argument definitions for `ralph machine`.
2//!
3//! Responsibilities:
4//! - Define the versioned machine-facing subcommands consumed by the macOS app.
5//! - Keep machine Clap wiring separate from execution logic.
6//! - Re-export request-shaping flags shared by the machine handlers.
7//!
8//! Not handled here:
9//! - JSON document emission.
10//! - Queue/task/run business logic.
11//! - Machine contract schema types.
12//!
13//! Invariants/assumptions:
14//! - Machine commands stay non-human-facing and versioned.
15//! - Subcommand shapes remain stable unless machine contract versions change.
16
17use clap::Args;
18use clap::Subcommand;
19
20use crate::agent;
21
22#[derive(Args)]
23pub struct MachineArgs {
24    #[command(subcommand)]
25    pub command: MachineCommand,
26}
27
28#[derive(Subcommand)]
29pub enum MachineCommand {
30    System(MachineSystemArgs),
31    Queue(MachineQueueArgs),
32    Config(MachineConfigArgs),
33    Workspace(MachineWorkspaceArgs),
34    Task(MachineTaskArgs),
35    Run(Box<MachineRunArgs>),
36    Doctor(MachineDoctorArgs),
37    CliSpec,
38    Schema,
39}
40
41#[derive(Args)]
42pub struct MachineSystemArgs {
43    #[command(subcommand)]
44    pub command: MachineSystemCommand,
45}
46
47#[derive(Subcommand)]
48pub enum MachineSystemCommand {
49    Info,
50}
51
52#[derive(Args)]
53pub struct MachineQueueArgs {
54    #[command(subcommand)]
55    pub command: MachineQueueCommand,
56}
57
58#[derive(Subcommand)]
59pub enum MachineQueueCommand {
60    Read,
61    Graph,
62    Dashboard(MachineDashboardArgs),
63    Validate,
64    Repair(MachineQueueRepairArgs),
65    Undo(MachineQueueUndoArgs),
66    UnlockInspect,
67}
68
69#[derive(Args)]
70pub struct MachineDashboardArgs {
71    #[arg(long, default_value_t = 30)]
72    pub days: u32,
73}
74
75#[derive(Args)]
76pub struct MachineQueueRepairArgs {
77    #[arg(long)]
78    pub dry_run: bool,
79}
80
81#[derive(Args)]
82pub struct MachineQueueUndoArgs {
83    #[arg(long, short)]
84    pub id: Option<String>,
85    #[arg(long)]
86    pub list: bool,
87    #[arg(long)]
88    pub dry_run: bool,
89}
90
91#[derive(Args)]
92pub struct MachineConfigArgs {
93    #[command(subcommand)]
94    pub command: MachineConfigCommand,
95}
96
97#[derive(Subcommand)]
98pub enum MachineConfigCommand {
99    Resolve,
100}
101
102#[derive(Args)]
103pub struct MachineWorkspaceArgs {
104    #[command(subcommand)]
105    pub command: MachineWorkspaceCommand,
106}
107
108#[derive(Subcommand)]
109pub enum MachineWorkspaceCommand {
110    Overview,
111}
112
113#[derive(Args)]
114pub struct MachineTaskArgs {
115    #[command(subcommand)]
116    pub command: MachineTaskCommand,
117}
118
119#[derive(Subcommand)]
120pub enum MachineTaskCommand {
121    Create(MachineTaskCreateArgs),
122    Mutate(MachineTaskMutateArgs),
123    Decompose(Box<MachineTaskDecomposeArgs>),
124}
125
126#[derive(Args)]
127pub struct MachineTaskCreateArgs {
128    #[arg(long, value_name = "PATH")]
129    pub input: Option<String>,
130}
131
132#[derive(Args)]
133pub struct MachineTaskMutateArgs {
134    #[arg(long, value_name = "PATH")]
135    pub input: Option<String>,
136    #[arg(long)]
137    pub dry_run: bool,
138}
139
140#[derive(Args)]
141pub struct MachineTaskDecomposeArgs {
142    pub source: Vec<String>,
143    #[arg(long)]
144    pub attach_to: Option<String>,
145    #[arg(long, default_value_t = 3)]
146    pub max_depth: u8,
147    #[arg(long, default_value_t = 5)]
148    pub max_children: u8,
149    #[arg(long, default_value_t = 50)]
150    pub max_nodes: u8,
151    #[arg(long, default_value = "draft")]
152    pub status: String,
153    #[arg(long, default_value = "fail")]
154    pub child_policy: String,
155    #[arg(long)]
156    pub with_dependencies: bool,
157    #[arg(long)]
158    pub write: bool,
159    #[command(flatten)]
160    pub agent: agent::AgentArgs,
161}
162
163#[derive(Args)]
164pub struct MachineRunArgs {
165    #[command(subcommand)]
166    pub command: MachineRunCommand,
167}
168
169#[derive(Subcommand)]
170pub enum MachineRunCommand {
171    One(MachineRunOneArgs),
172    Loop(MachineRunLoopArgs),
173    ParallelStatus,
174}
175
176#[derive(Args)]
177pub struct MachineRunOneArgs {
178    #[arg(long)]
179    pub id: Option<String>,
180    #[arg(long)]
181    pub force: bool,
182    #[arg(long)]
183    pub resume: bool,
184    #[command(flatten)]
185    pub agent: agent::RunAgentArgs,
186}
187
188#[derive(Args)]
189pub struct MachineRunLoopArgs {
190    #[arg(long, default_value_t = 0)]
191    pub max_tasks: u32,
192    #[arg(long)]
193    pub force: bool,
194    #[arg(long)]
195    pub resume: bool,
196    #[arg(
197        long,
198        value_parser = clap::value_parser!(u8).range(2..),
199        num_args = 0..=1,
200        default_missing_value = "2",
201        value_name = "N",
202    )]
203    pub parallel: Option<u8>,
204    #[command(flatten)]
205    pub agent: agent::RunAgentArgs,
206}
207
208#[derive(Args)]
209pub struct MachineDoctorArgs {
210    #[command(subcommand)]
211    pub command: MachineDoctorCommand,
212}
213
214#[derive(Subcommand)]
215pub enum MachineDoctorCommand {
216    Report,
217}