1use clap::{Args, Subcommand};
18
19mod batch;
21mod build;
22mod decompose;
23mod edit;
24mod lifecycle;
25mod relations;
26mod template;
27mod types;
28
29pub use batch::{
31 BatchEditArgs, BatchFieldArgs, BatchOperation, BatchSelectArgs, BatchStatusArgs, TaskBatchArgs,
32};
33pub use build::{TaskBuildArgs, TaskBuildRefactorArgs};
34pub use decompose::TaskDecomposeArgs;
35pub use edit::{TaskEditArgs, TaskFieldArgs, TaskUpdateArgs};
36pub use lifecycle::{
37 TaskDoneArgs, TaskReadyArgs, TaskRejectArgs, TaskScheduleArgs, TaskShowArgs, TaskStartArgs,
38 TaskStatusArgs,
39};
40pub use relations::{
41 TaskBlocksArgs, TaskChildrenArgs, TaskCloneArgs, TaskMarkDuplicateArgs, TaskParentArgs,
42 TaskRelateArgs, TaskRelationFormat, TaskSplitArgs,
43};
44pub use template::{
45 TaskFromArgs, TaskFromCommand, TaskFromTemplateArgs, TaskTemplateArgs, TaskTemplateBuildArgs,
46 TaskTemplateCommand, TaskTemplateShowArgs,
47};
48pub use types::{
49 BatchMode, TaskDecomposeChildPolicyArg, TaskDecomposeFormatArg, TaskEditFieldArg, TaskStatusArg,
50};
51
52#[derive(Args)]
53#[command(
54 about = "Create and build tasks from freeform requests",
55 subcommand_required = false,
56 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"
57)]
58pub struct TaskArgs {
59 #[command(subcommand)]
60 pub command: Option<TaskCommand>,
61
62 #[command(flatten)]
63 pub build: TaskBuildArgs,
64}
65
66#[derive(Subcommand)]
67pub enum TaskCommand {
68 #[command(
70 next_help_heading = "Create and build",
71 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\""
72 )]
73 Build(TaskBuildArgs),
74
75 #[command(
77 next_help_heading = "Create and build",
78 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\""
79 )]
80 Decompose(TaskDecomposeArgs),
81
82 #[command(
84 next_help_heading = "Create and build",
85 alias = "ref",
86 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"
87 )]
88 Refactor(TaskBuildRefactorArgs),
89
90 #[command(
92 next_help_heading = "Create and build",
93 name = "build-refactor",
94 after_long_help = "Alternative command name. Prefer 'ralph task refactor'.\n\nExamples:\n ralph task build-refactor\n ralph task build-refactor --threshold 700"
95 )]
96 BuildRefactor(TaskBuildRefactorArgs),
97
98 #[command(
100 next_help_heading = "Lifecycle",
101 alias = "details",
102 after_long_help = "Examples:\n ralph task show RQ-0001\n ralph task details RQ-0001 --format compact"
103 )]
104 Show(TaskShowArgs),
105
106 #[command(
108 next_help_heading = "Lifecycle",
109 after_long_help = "Examples:\n ralph task ready RQ-0005\n ralph task ready --note \"Ready for implementation\" RQ-0005"
110 )]
111 Ready(TaskReadyArgs),
112
113 #[command(
117 next_help_heading = "Lifecycle",
118 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"
119 )]
120 Status(TaskStatusArgs),
121
122 #[command(
124 next_help_heading = "Lifecycle",
125 after_long_help = "Examples:\n ralph task done RQ-0001\n ralph task done --note \"Finished work\" --note \"make ci green\" RQ-0001"
126 )]
127 Done(TaskDoneArgs),
128
129 #[command(
131 next_help_heading = "Lifecycle",
132 alias = "rejected",
133 after_long_help = "Examples:\n ralph task reject RQ-0002\n ralph task reject --note \"No longer needed\" RQ-0002"
134 )]
135 Reject(TaskRejectArgs),
136
137 #[command(
139 next_help_heading = "Edit",
140 after_long_help = "Examples:\n ralph task field severity high RQ-0001\n ralph task field complexity \"O(n log n)\" RQ-0002"
141 )]
142 Field(TaskFieldArgs),
143
144 #[command(
151 next_help_heading = "Edit",
152 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"
153 )]
154 Edit(TaskEditArgs),
155
156 #[command(
158 next_help_heading = "Edit",
159 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"
160 )]
161 Update(TaskUpdateArgs),
162
163 #[command(
165 next_help_heading = "Batch and templates",
166 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"
167 )]
168 Template(TaskTemplateArgs),
169
170 #[command(
172 next_help_heading = "Relationships",
173 alias = "duplicate",
174 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"
175 )]
176 Clone(TaskCloneArgs),
177
178 #[command(
180 next_help_heading = "Batch and templates",
181 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\""
182 )]
183 Batch(TaskBatchArgs),
184
185 #[command(
187 next_help_heading = "Lifecycle",
188 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"
189 )]
190 Schedule(TaskScheduleArgs),
191
192 #[command(
194 next_help_heading = "Relationships",
195 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"
196 )]
197 Relate(TaskRelateArgs),
198
199 #[command(
201 next_help_heading = "Relationships",
202 after_long_help = "Examples:\n ralph task blocks RQ-0001 RQ-0002\n ralph task blocks RQ-0001 RQ-0002 RQ-0003"
203 )]
204 Blocks(TaskBlocksArgs),
205
206 #[command(
208 next_help_heading = "Relationships",
209 name = "mark-duplicate",
210 after_long_help = "Examples:\n ralph task mark-duplicate RQ-0001 RQ-0002"
211 )]
212 MarkDuplicate(TaskMarkDuplicateArgs),
213
214 #[command(
216 next_help_heading = "Relationships",
217 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"
218 )]
219 Split(TaskSplitArgs),
220
221 #[command(
223 next_help_heading = "Lifecycle",
224 after_long_help = "Examples:\n ralph task start RQ-0001\n ralph task start --reset RQ-0001"
225 )]
226 Start(TaskStartArgs),
227
228 #[command(
230 next_help_heading = "Relationships",
231 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"
232 )]
233 Children(TaskChildrenArgs),
234
235 #[command(
237 next_help_heading = "Relationships",
238 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"
239 )]
240 Parent(TaskParentArgs),
241
242 #[command(
247 name = "from",
248 next_help_heading = "Batch and templates",
249 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."
250 )]
251 From(TaskFromArgs),
252}