Skip to main content

ralph/cli/task/args/
mod.rs

1//! CLI argument definitions for `ralph task ...` commands.
2//!
3//! Responsibilities:
4//! - Define all `#[derive(Args)]` structs for task subcommands.
5//! - Define all `#[derive(Subcommand)]` enums for command routing.
6//! - Define all `#[derive(ValueEnum)]` enums for typed arguments.
7//! - Provide conversions from CLI types to internal types.
8//!
9//! Not handled here:
10//! - Command execution logic (see individual handler modules).
11//! - Business logic or queue operations.
12//!
13//! Invariants/assumptions:
14//! - All argument types must be `Clone` where needed for clap flattening.
15//! - Defaults should match the behavior described in help text.
16
17use clap::{Args, Subcommand};
18
19// Submodules
20mod batch;
21mod build;
22mod decompose;
23mod edit;
24mod lifecycle;
25mod mutate;
26mod relations;
27mod template;
28mod types;
29
30// Re-exports for backward compatibility
31pub use batch::{
32    BatchEditArgs, BatchFieldArgs, BatchOperation, BatchSelectArgs, BatchStatusArgs, TaskBatchArgs,
33};
34pub use build::{TaskBuildArgs, TaskBuildRefactorArgs};
35pub use decompose::TaskDecomposeArgs;
36pub use edit::{TaskEditArgs, TaskFieldArgs, TaskUpdateArgs};
37pub use lifecycle::{
38    TaskDoneArgs, TaskReadyArgs, TaskRejectArgs, TaskScheduleArgs, TaskShowArgs, TaskStartArgs,
39    TaskStatusArgs,
40};
41pub use mutate::TaskMutateArgs;
42pub use relations::{
43    TaskBlocksArgs, TaskChildrenArgs, TaskCloneArgs, TaskMarkDuplicateArgs, TaskParentArgs,
44    TaskRelateArgs, TaskRelationFormat, TaskSplitArgs,
45};
46pub use template::{
47    TaskFromArgs, TaskFromCommand, TaskFromTemplateArgs, TaskTemplateArgs, TaskTemplateBuildArgs,
48    TaskTemplateCommand, TaskTemplateShowArgs,
49};
50pub use types::{
51    BatchMode, TaskDecomposeChildPolicyArg, TaskDecomposeFormatArg, TaskEditFieldArg, TaskStatusArg,
52};
53
54#[derive(Args)]
55#[command(
56    about = "Create and build tasks from freeform requests",
57    subcommand_required = false,
58    after_long_help = "Common journeys:\n - Create a task:\n   ralph task \"Refactor queue parsing\"\n   ralph task build-refactor\n - Start work on a task:\n   ralph task ready RQ-0001\n   ralph task start RQ-0001\n - Complete a task:\n   ralph task status done RQ-0001\n   ralph task done --note \"Build checks pass\" RQ-0001\n - Split a task:\n   ralph task split RQ-0001\n   ralph task split --number 3 RQ-0001\n\nCommand intent sections:\nCreate and build: task, build, refactor, build-refactor\nLifecycle: show, ready, status, done, reject, start, schedule\nEdit: field, edit, update\nRelationships: clone, split, relate, blocks, mark-duplicate, children, parent\nBatch and templates: batch, template"
59)]
60pub struct TaskArgs {
61    #[command(subcommand)]
62    pub command: Option<TaskCommand>,
63
64    #[command(flatten)]
65    pub build: TaskBuildArgs,
66}
67
68#[derive(Subcommand)]
69pub enum TaskCommand {
70    /// Build a new task from a natural language request.
71    #[command(
72        next_help_heading = "Create and build",
73        after_long_help = "Runner selection:\n - Override runner/model/effort for this invocation using flags.\n - Defaults come from config when flags are omitted.\n\nRunner CLI options:\n - Override approval/sandbox/verbosity/plan-mode via flags.\n - Unsupported options follow --unsupported-option-policy.\n\nExamples:\n ralph task \"Add integration tests for run one\"\n ralph task --tags cli,rust \"Refactor queue parsing\"\n ralph task --scope crates/ralph \"Fix queue graph output\"\n ralph task --runner opencode --model gpt-5.2 \"Add docs for OpenCode setup\"\n ralph task --runner gemini --model gemini-3-flash-preview \"Draft risk checklist\"\n ralph task --runner pi --model gpt-5.2 \"Draft risk checklist\"\n ralph task --runner codex --model gpt-5.4 --effort high \"Fix queue validation\"\n ralph task --approval-mode auto-edits --runner claude \"Audit approvals\"\n ralph task --sandbox disabled --runner codex \"Audit sandbox\"\n ralph task --repo-prompt plan \"Audit error handling\"\n ralph task --repo-prompt off \"Quick typo fix\"\n echo \"Triage flaky CI\" | ralph task --runner codex --model gpt-5.4 --effort medium\n\nExplicit subcommand:\n ralph task build \"Add integration tests for run one\""
74    )]
75    Build(TaskBuildArgs),
76
77    /// Recursively decompose a goal or existing task into a task tree.
78    #[command(
79        next_help_heading = "Create and build",
80        after_long_help = "Runner selection:\n - Override runner/model/effort for this invocation using flags.\n - Defaults come from config when flags are omitted.\n\nPlanner behavior:\n - Preview is the default; use --write to mutate queue state.\n - Existing tasks are preserved as parents unless --attach-to is used for a freeform request.\n - Existing parents with children are blocked by default; use --child-policy append|replace to proceed.\n - Use --with-dependencies to infer sibling depends_on edges.\n - Use --format json for stable machine-readable output.\n\nExamples:\n ralph task decompose \"Build OAuth login with GitHub and Google\"\n ralph task decompose \"Improve webhook reliability\" --write\n ralph task decompose RQ-0123 --max-depth 3 --preview\n ralph task decompose RQ-0123 --child-policy append --with-dependencies --write\n ralph task decompose --attach-to RQ-0042 \"Plan webhook reliability work\" --write\n ralph task decompose --attach-to RQ-0042 --child-policy replace --format json \"Rebuild the auth subtree\"\n ralph task decompose --runner codex --model gpt-5.4 --effort high \"Plan queue migration\""
81    )]
82    Decompose(TaskDecomposeArgs),
83
84    /// Automatically create refactoring tasks for large files.
85    #[command(
86        next_help_heading = "Create and build",
87        alias = "ref",
88        after_long_help = "Examples:\n ralph task refactor\n ralph task refactor --threshold 700\n ralph task refactor --path crates/ralph/src/cli\n ralph task refactor --dry-run --threshold 500\n ralph task refactor --batch never\n ralph task refactor --tags urgent,technical-debt\n ralph task ref --threshold 800"
89    )]
90    Refactor(TaskBuildRefactorArgs),
91
92    /// Automatically create refactoring tasks for large files (alternative to 'refactor').
93    #[command(
94        next_help_heading = "Create and build",
95        name = "build-refactor",
96        after_long_help = "Alternative command name. Prefer 'ralph task refactor'.\n\nExamples:\n ralph task build-refactor\n ralph task build-refactor --threshold 700"
97    )]
98    BuildRefactor(TaskBuildRefactorArgs),
99
100    /// Show a task by ID (queue + done).
101    #[command(
102        next_help_heading = "Lifecycle",
103        alias = "details",
104        after_long_help = "Examples:\n ralph task show RQ-0001\n ralph task details RQ-0001 --format compact"
105    )]
106    Show(TaskShowArgs),
107
108    /// Promote a draft task to todo.
109    #[command(
110        next_help_heading = "Lifecycle",
111        after_long_help = "Examples:\n ralph task ready RQ-0005\n ralph task ready --note \"Ready for implementation\" RQ-0005"
112    )]
113    Ready(TaskReadyArgs),
114
115    /// Update a task's status (draft, todo, doing, done, rejected).
116    ///
117    /// Note: terminal statuses (done, rejected) complete and archive the task.
118    #[command(
119        next_help_heading = "Lifecycle",
120        after_long_help = "Examples:\n ralph task status doing RQ-0001\n ralph task status doing --note \"Starting work\" RQ-0001\n ralph task status todo --note \"Back to backlog\" RQ-0001\n ralph task status done RQ-0001\n ralph task status rejected --note \"Invalid request\" RQ-0002"
121    )]
122    Status(TaskStatusArgs),
123
124    /// Complete a task as done and move it to the done archive.
125    #[command(
126        next_help_heading = "Lifecycle",
127        after_long_help = "Examples:\n ralph task done RQ-0001\n ralph task done --note \"Finished work\" --note \"make ci green\" RQ-0001"
128    )]
129    Done(TaskDoneArgs),
130
131    /// Complete a task as rejected and move it to the done archive.
132    #[command(
133        next_help_heading = "Lifecycle",
134        alias = "rejected",
135        after_long_help = "Examples:\n ralph task reject RQ-0002\n ralph task reject --note \"No longer needed\" RQ-0002"
136    )]
137    Reject(TaskRejectArgs),
138
139    /// Set a custom field on a task.
140    #[command(
141        next_help_heading = "Edit",
142        after_long_help = "Examples:\n ralph task field severity high RQ-0001\n ralph task field complexity \"O(n log n)\" RQ-0002"
143    )]
144    Field(TaskFieldArgs),
145
146    /// Edit any task field (default or custom).
147    ///
148    /// Side effect: When auto_archive_terminal_after_days is configured in the queue
149    /// settings, this command may auto-archive terminal tasks (Done/Rejected) that
150    /// are older than the configured threshold. The command output will list which
151    /// specific tasks were archived. Use --no-auto-archive to disable this behavior.
152    #[command(
153        next_help_heading = "Edit",
154        after_long_help = "Examples:\n ralph task edit title \"Clarify CLI edit\" RQ-0001\n ralph task edit status doing RQ-0001\n ralph task edit priority high RQ-0001\n ralph task edit tags \"cli, rust\" RQ-0001\n ralph task edit custom_fields \"severity=high, owner=ralph\" RQ-0001\n ralph task edit agent '{\"runner\":\"codex\",\"model\":\"gpt-5.4\",\"phases\":2}' RQ-0001\n ralph task edit request \"\" RQ-0001\n ralph task edit completed_at \"2026-01-20T12:00:00Z\" RQ-0001\n ralph task edit --dry-run title \"Preview change\" RQ-0001\n ralph task edit --no-auto-archive title \"Update without archiving\" RQ-0001"
155    )]
156    Edit(TaskEditArgs),
157
158    /// Apply a structured multi-field task mutation transaction.
159    #[command(
160        next_help_heading = "Edit",
161        after_long_help = "Examples:\n echo '{\"version\":1,\"atomic\":true,\"tasks\":[{\"task_id\":\"RQ-0001\",\"edits\":[{\"field\":\"title\",\"value\":\"Clarified title\"},{\"field\":\"priority\",\"value\":\"high\"}]}]}' | ralph task mutate\n ralph task mutate --input /tmp/task-mutation.json\n ralph task mutate --dry-run --input /tmp/task-mutation.json"
162    )]
163    Mutate(TaskMutateArgs),
164
165    /// Update existing task fields based on current repository state.
166    #[command(
167        next_help_heading = "Edit",
168        after_long_help = "Runner selection:\n - Override runner/model/effort for this invocation using flags.\n - Defaults come from config when flags are omitted.\n\nRunner CLI options:\n - Override approval/sandbox/verbosity/plan-mode via flags.\n - Unsupported options follow --unsupported-option-policy.\n\nField selection:\n - By default, all updatable fields are refreshed: scope, evidence, plan, notes, tags, depends_on.\n - Use --fields to specify which fields to update.\n\nTask selection:\n - Omit TASK_ID to update every task in the active queue.\n\nExamples:\n ralph task update\n ralph task update RQ-0001\n ralph task update --fields scope,evidence,plan RQ-0001\n ralph task update --runner opencode --model gpt-5.2 RQ-0001\n ralph task update --approval-mode auto-edits --runner claude RQ-0001\n ralph task update --repo-prompt plan RQ-0001\n ralph task update --repo-prompt off --fields scope,evidence RQ-0001\n ralph task update --fields tags RQ-0042\n ralph task update --dry-run RQ-0001"
169    )]
170    Update(TaskUpdateArgs),
171
172    /// Manage task templates for common task types.
173    #[command(
174        next_help_heading = "Batch and templates",
175        after_long_help = "Examples:\n ralph task template list\n ralph task template show bug\n ralph task template show add-tests\n ralph task template build bug \"Fix login timeout\"\n ralph task template build add-tests src/module.rs \"Add tests for module\"\n ralph task template build refactor-performance src/bottleneck.rs \"Optimize performance\"\n\nAvailable templates:\n - bug: Bug fix with reproduction steps and regression tests\n - feature: New feature with design, implementation, and documentation\n - refactor: Code refactoring with behavior preservation\n - test: Test addition or improvement\n - docs: Documentation update or creation\n - add-tests: Add tests for existing code with coverage verification\n - refactor-performance: Optimize performance with profiling and benchmarking\n - fix-error-handling: Fix error handling with proper types and context\n - add-docs: Add documentation for a specific file or module\n - security-audit: Security audit with vulnerability checks"
176    )]
177    Template(TaskTemplateArgs),
178
179    /// Clone an existing task to create a new task from it.
180    #[command(
181        next_help_heading = "Relationships",
182        alias = "duplicate",
183        after_long_help = "Examples:\n ralph task clone RQ-0001\n ralph task clone RQ-0001 --status todo\n ralph task clone RQ-0001 --title-prefix \"[Follow-up] \"\n ralph task clone RQ-0001 --dry-run\n ralph task duplicate RQ-0001"
184    )]
185    Clone(TaskCloneArgs),
186
187    /// Perform batch operations on multiple tasks efficiently.
188    #[command(
189        next_help_heading = "Batch and templates",
190        after_long_help = "Examples:\n ralph task batch status doing RQ-0001 RQ-0002 RQ-0003\n ralph task batch status done --tag-filter ready\n ralph task batch field priority high --tag-filter urgent\n ralph task batch edit tags \"reviewed\" --tag-filter rust\n ralph task batch --dry-run status doing --tag-filter cli\n ralph task batch --continue-on-error status doing RQ-0001 RQ-0002 RQ-9999\n ralph task batch delete RQ-0001 RQ-0002\n ralph task batch delete --tag-filter stale --older-than 30d\n ralph task batch archive --tag-filter done --status-filter done\n ralph task batch clone --tag-filter template --status todo --title-prefix \"[Sprint] \"\n ralph task batch split --tag-filter epic --number 3 --distribute-plan\n ralph task batch plan-append --tag-filter rust --plan-item \"Run make ci\"\n ralph task batch plan-prepend RQ-0001 --plan-item \"Confirm repro\""
191    )]
192    Batch(TaskBatchArgs),
193
194    /// Schedule a task to start after a specific time.
195    #[command(
196        next_help_heading = "Lifecycle",
197        after_long_help = "Examples:\n ralph task schedule RQ-0001 '2026-02-01T09:00:00Z'\n ralph task schedule RQ-0001 'tomorrow 9am'\n ralph task schedule RQ-0001 'in 2 hours'\n ralph task schedule RQ-0001 'next monday'\n ralph task schedule RQ-0001 --clear"
198    )]
199    Schedule(TaskScheduleArgs),
200
201    /// Add a relationship between tasks.
202    #[command(
203        next_help_heading = "Relationships",
204        after_long_help = "Examples:\n ralph task relate RQ-0001 blocks RQ-0002\n ralph task relate RQ-0001 relates_to RQ-0003\n ralph task relate RQ-0001 duplicates RQ-0004"
205    )]
206    Relate(TaskRelateArgs),
207
208    /// Mark a task as blocking another task (shorthand for `relate <task> blocks <blocked>`).
209    #[command(
210        next_help_heading = "Relationships",
211        after_long_help = "Examples:\n ralph task blocks RQ-0001 RQ-0002\n ralph task blocks RQ-0001 RQ-0002 RQ-0003"
212    )]
213    Blocks(TaskBlocksArgs),
214
215    /// Mark a task as a duplicate of another task (shorthand for `relate <task> duplicates <original>`).
216    #[command(
217        next_help_heading = "Relationships",
218        name = "mark-duplicate",
219        after_long_help = "Examples:\n ralph task mark-duplicate RQ-0001 RQ-0002"
220    )]
221    MarkDuplicate(TaskMarkDuplicateArgs),
222
223    /// Split a task into multiple child tasks for better granularity.
224    #[command(
225        next_help_heading = "Relationships",
226        after_long_help = "Examples:\n ralph task split RQ-0001\n ralph task split --number 3 RQ-0001\n ralph task split --status todo --number 2 RQ-0001\n ralph task split --distribute-plan RQ-0001"
227    )]
228    Split(TaskSplitArgs),
229
230    /// Start work on a task (sets started_at and moves it to doing).
231    #[command(
232        next_help_heading = "Lifecycle",
233        after_long_help = "Examples:\n ralph task start RQ-0001\n ralph task start --reset RQ-0001"
234    )]
235    Start(TaskStartArgs),
236
237    /// List child tasks for a given task (based on parent_id).
238    #[command(
239        next_help_heading = "Relationships",
240        after_long_help = "Examples:\n ralph task children RQ-0001\n ralph task children RQ-0001 --recursive\n ralph task children RQ-0001 --include-done\n ralph task children RQ-0001 --format json"
241    )]
242    Children(TaskChildrenArgs),
243
244    /// Show the parent task for a given task (based on parent_id).
245    #[command(
246        next_help_heading = "Relationships",
247        after_long_help = "Examples:\n ralph task parent RQ-0002\n ralph task parent RQ-0002 --include-done\n ralph task parent RQ-0002 --format json"
248    )]
249    Parent(TaskParentArgs),
250
251    /// Build a task from a template with variable substitution.
252    ///
253    /// This is a convenience command that combines template selection,
254    /// variable substitution, and task creation in one step.
255    #[command(
256        name = "from",
257        next_help_heading = "Batch and templates",
258        after_long_help = "Examples:\n  ralph task from template bug --title \"Fix login timeout\"\n  ralph task from template feature --title \"Add dark mode\" --set target=src/ui/theme.rs\n  ralph task from template add-tests --title \"Test auth\" --set target=src/auth/mod.rs\n\nSee 'ralph task template list' for available templates."
259    )]
260    From(TaskFromArgs),
261}