1use clap::{Args, Subcommand};
18
19mod batch;
21mod build;
22mod decompose;
23mod edit;
24mod lifecycle;
25mod mutate;
26mod relations;
27mod template;
28mod types;
29
30pub 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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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}