cli.rs

  1use clap::{Parser, Subcommand};
  2
  3#[derive(Parser)]
  4#[command(name = "td", version, about = "Todo tracker for AI agents")]
  5pub struct Cli {
  6    /// Output JSON
  7    #[arg(short = 'j', long = "json", global = true)]
  8    pub json: bool,
  9
 10    /// Select a project explicitly (overrides cwd binding)
 11    #[arg(long, global = true)]
 12    pub project: Option<String>,
 13
 14    #[command(subcommand)]
 15    pub command: Command,
 16}
 17
 18#[derive(Subcommand)]
 19pub enum Command {
 20    /// Manage projects
 21    Project {
 22        #[command(subcommand)]
 23        action: ProjectAction,
 24    },
 25
 26    /// Create a new task
 27    #[command(visible_alias = "add")]
 28    Create {
 29        /// Task title
 30        title: Option<String>,
 31
 32        /// Priority (low, medium, high)
 33        #[arg(short, long, default_value = "medium")]
 34        priority: String,
 35
 36        /// Effort (low, medium, high)
 37        #[arg(short, long, default_value = "medium")]
 38        effort: String,
 39
 40        /// Task type
 41        #[arg(short = 't', long = "type", default_value = "task")]
 42        task_type: String,
 43
 44        /// Description
 45        #[arg(short = 'd', long = "desc")]
 46        desc: Option<String>,
 47
 48        /// Parent task ID (creates a subtask)
 49        #[arg(long)]
 50        parent: Option<String>,
 51
 52        /// Labels (comma-separated)
 53        #[arg(short, long)]
 54        labels: Option<String>,
 55    },
 56
 57    /// List tasks
 58    #[command(visible_alias = "ls")]
 59    List {
 60        /// Filter by status
 61        #[arg(short, long)]
 62        status: Option<String>,
 63
 64        /// Filter by priority (low, medium, high)
 65        #[arg(short, long)]
 66        priority: Option<String>,
 67
 68        /// Filter by effort (low, medium, high)
 69        #[arg(short, long)]
 70        effort: Option<String>,
 71
 72        /// Filter by label
 73        #[arg(short, long)]
 74        label: Option<String>,
 75    },
 76
 77    /// Show task details
 78    Show {
 79        /// Task ID
 80        id: String,
 81    },
 82
 83    /// Append a work log entry to a task
 84    Log {
 85        /// Task ID
 86        id: String,
 87        /// Log entry body
 88        message: String,
 89    },
 90
 91    /// Update a task
 92    Update {
 93        /// Task ID
 94        id: String,
 95
 96        /// Set status
 97        #[arg(short, long)]
 98        status: Option<String>,
 99
100        /// Set priority (low, medium, high)
101        #[arg(short, long)]
102        priority: Option<String>,
103
104        /// Set effort (low, medium, high)
105        #[arg(short, long)]
106        effort: Option<String>,
107
108        /// Set title
109        #[arg(short = 't', long)]
110        title: Option<String>,
111
112        /// Set description
113        #[arg(short = 'd', long = "desc")]
114        desc: Option<String>,
115    },
116
117    /// Mark task(s) as closed
118    #[command(visible_alias = "close")]
119    Done {
120        /// Task IDs
121        #[arg(required = true)]
122        ids: Vec<String>,
123    },
124
125    /// Delete task(s)
126    Rm {
127        /// Skip warnings about dependents becoming unblocked
128        #[arg(short, long)]
129        force: bool,
130
131        /// Delete the whole subtree (task and descendants)
132        #[arg(short = 'r', long)]
133        recursive: bool,
134
135        /// Task IDs
136        #[arg(required = true)]
137        ids: Vec<String>,
138    },
139
140    /// Reopen task(s)
141    Reopen {
142        /// Task IDs
143        #[arg(required = true)]
144        ids: Vec<String>,
145    },
146
147    /// Manage dependencies / blockers
148    Dep {
149        #[command(subcommand)]
150        action: DepAction,
151    },
152
153    /// Manage labels
154    Label {
155        #[command(subcommand)]
156        action: LabelAction,
157    },
158
159    /// Search tasks by title or description
160    Search {
161        /// Search query
162        query: String,
163    },
164
165    /// Show tasks with no open blockers
166    Ready,
167
168    /// Recommend next task(s) to work on
169    Next {
170        /// Scoring strategy: impact (default) or effort
171        #[arg(short, long, default_value = "impact")]
172        mode: String,
173
174        /// Show signal breakdown and equation
175        #[arg(short, long)]
176        verbose: bool,
177
178        /// Maximum number of results
179        #[arg(short = 'n', long = "limit", default_value = "5")]
180        limit: usize,
181    },
182
183    /// Show task statistics (always JSON)
184    Stats,
185
186    /// Compact accumulated delta files into the base snapshot
187    Tidy,
188
189    /// Export tasks to JSONL (one JSON object per line)
190    Export,
191
192    /// Import tasks from a JSONL file
193    Import {
194        /// Path to JSONL file (- for stdin)
195        file: String,
196    },
197
198    /// Sync project state with a peer via magic wormhole
199    Sync {
200        /// Wormhole code to connect to a peer (omit to generate one)
201        code: Option<String>,
202    },
203
204    /// Install the agent skill file (SKILL.md)
205    Skill {
206        /// Skills directory (writes managing-tasks-with-td/SKILL.md inside)
207        #[arg(long)]
208        dir: Option<String>,
209    },
210}
211
212#[derive(Subcommand)]
213pub enum DepAction {
214    /// Add a dependency (child is blocked by parent)
215    Add {
216        /// Task that is blocked
217        child: String,
218        /// Task that blocks it
219        parent: String,
220    },
221    /// Remove a dependency
222    Rm {
223        /// Task that was blocked
224        child: String,
225        /// Task that was blocking
226        parent: String,
227    },
228    /// Show child tasks
229    Tree {
230        /// Parent task ID
231        id: String,
232    },
233}
234
235#[derive(Subcommand)]
236pub enum LabelAction {
237    /// Add a label to a task
238    Add {
239        /// Task ID
240        id: String,
241        /// Label to add
242        label: String,
243    },
244    /// Remove a label from a task
245    Rm {
246        /// Task ID
247        id: String,
248        /// Label to remove
249        label: String,
250    },
251    /// List labels on a task
252    List {
253        /// Task ID
254        id: String,
255    },
256    /// List all distinct labels
257    ListAll,
258}
259
260#[derive(Subcommand)]
261pub enum ProjectAction {
262    /// Initialise a central project and bind the current directory to it
263    Init {
264        /// Project name
265        name: String,
266    },
267    /// Bind the current directory to an existing project
268    Bind {
269        /// Project name
270        name: String,
271    },
272    /// Remove the binding for the current directory
273    Unbind,
274    /// Delete a project from central storage and remove all directory bindings
275    Delete {
276        /// Project name
277        name: String,
278    },
279    /// List all known projects in central storage
280    List,
281}