clickup-cli 0.9.1

CLI for the ClickUp API, optimized for AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
use crate::client::ClickUpClient;
use crate::commands::auth::resolve_token;
use crate::commands::workspace::resolve_workspace;
use crate::error::CliError;
use crate::git;
use crate::output::OutputConfig;
use crate::Cli;
use clap::Subcommand;

#[derive(Subcommand)]
pub enum TaskCommands {
    /// List tasks in a list
    List {
        /// List ID
        #[arg(long)]
        list: String,
        /// Filter by status
        #[arg(long)]
        status: Option<Vec<String>>,
        /// Filter by assignee
        #[arg(long)]
        assignee: Option<Vec<String>>,
        /// Filter by tag
        #[arg(long)]
        tag: Option<Vec<String>>,
        /// Include closed tasks
        #[arg(long)]
        include_closed: bool,
        /// Order by field
        #[arg(long)]
        order_by: Option<String>,
        /// Reverse sort order
        #[arg(long)]
        reverse: bool,
    },
    /// Search tasks across workspace
    Search {
        /// Filter by space
        #[arg(long)]
        space: Option<String>,
        /// Filter by folder
        #[arg(long)]
        folder: Option<String>,
        /// Filter by list
        #[arg(long)]
        list: Option<String>,
        /// Filter by status
        #[arg(long)]
        status: Option<Vec<String>>,
        /// Filter by assignee
        #[arg(long)]
        assignee: Option<Vec<String>>,
        /// Filter by tag
        #[arg(long)]
        tag: Option<Vec<String>>,
    },
    /// Get task details
    Get {
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
        /// Include subtasks
        #[arg(long)]
        subtasks: bool,
        /// Treat ID as custom task ID
        #[arg(long)]
        custom_task_id: bool,
    },
    /// Create a task
    Create {
        /// List ID
        #[arg(long)]
        list: String,
        /// Task name
        #[arg(long)]
        name: String,
        /// Description
        #[arg(long)]
        description: Option<String>,
        /// Status
        #[arg(long)]
        status: Option<String>,
        /// Priority (1=urgent, 2=high, 3=normal, 4=low)
        #[arg(long)]
        priority: Option<u8>,
        /// Assignee user ID
        #[arg(long)]
        assignee: Option<Vec<String>>,
        /// Tag name
        #[arg(long)]
        tag: Option<Vec<String>>,
        /// Due date (YYYY-MM-DD)
        #[arg(long)]
        due_date: Option<String>,
        /// Parent task ID (creates subtask)
        #[arg(long)]
        parent: Option<String>,
    },
    /// Update a task
    Update {
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
        /// New name
        #[arg(long)]
        name: Option<String>,
        /// New status
        #[arg(long)]
        status: Option<String>,
        /// New priority (1-4)
        #[arg(long)]
        priority: Option<u8>,
        /// Add assignee
        #[arg(long)]
        add_assignee: Option<Vec<String>>,
        /// Remove assignee
        #[arg(long)]
        rem_assignee: Option<Vec<String>>,
        /// New description
        #[arg(long)]
        description: Option<String>,
    },
    /// Delete a task (explicit ID required — never auto-detects from branch)
    Delete {
        /// Task ID
        id: Option<String>,
    },
    /// Get time in status for task(s)
    TimeInStatus {
        /// Task ID(s) — multiple IDs triggers bulk mode
        ids: Vec<String>,
    },
    /// Add a tag to a task. Usage: add-tag <task_id> <tag_name>  OR  add-tag <tag_name> (task auto-detected from branch)
    AddTag {
        /// Task ID (or tag name if only one arg is given)
        task_or_tag: String,
        /// Tag name (when task_or_tag is a task ID)
        tag_name: Option<String>,
    },
    /// Remove a tag from a task. Usage: remove-tag <task_id> <tag_name>  OR  remove-tag <tag_name> (task auto-detected)
    RemoveTag {
        /// Task ID (or tag name if only one arg is given)
        task_or_tag: String,
        /// Tag name (when task_or_tag is a task ID)
        tag_name: Option<String>,
    },
    /// Add a dependency to a task
    #[command(name = "add-dep")]
    AddDep {
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
        /// This task depends on another task (task is a blocker)
        #[arg(long, conflicts_with = "dependency_of")]
        depends_on: Option<String>,
        /// This task is a dependency of another task (task is blocked by)
        #[arg(long)]
        dependency_of: Option<String>,
    },
    /// Remove a dependency from a task
    #[command(name = "remove-dep")]
    RemoveDep {
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
        /// Remove depends-on relationship with this task ID
        #[arg(long, conflicts_with = "dependency_of")]
        depends_on: Option<String>,
        /// Remove dependency-of relationship with this task ID
        #[arg(long)]
        dependency_of: Option<String>,
    },
    /// Link two tasks together
    Link {
        /// Task ID
        id: String,
        /// Target task ID to link to
        target_id: String,
    },
    /// Unlink two tasks
    Unlink {
        /// Task ID
        id: String,
        /// Target task ID to unlink from
        target_id: String,
    },
    /// Move a task to a different list (v3)
    Move {
        /// Destination list ID
        #[arg(long)]
        list: String,
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
    },
    /// Set per-user time estimate on a task (v3)
    #[command(name = "set-estimate")]
    SetEstimate {
        /// Assignee user ID
        #[arg(long)]
        assignee: String,
        /// Time estimate in milliseconds
        #[arg(long)]
        time: u64,
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
    },
    /// Replace all per-user time estimates on a task (v3)
    #[command(name = "replace-estimates")]
    ReplaceEstimates {
        /// Assignee user ID
        #[arg(long)]
        assignee: String,
        /// Time estimate in milliseconds
        #[arg(long)]
        time: u64,
        /// Task ID (auto-detected from git branch if omitted)
        id: Option<String>,
    },
}

const TASK_FIELDS: &[&str] = &["id", "name", "status", "priority", "assignees", "due_date"];

pub async fn execute(command: TaskCommands, cli: &Cli) -> Result<(), CliError> {
    let token = resolve_token(cli)?;
    let client = ClickUpClient::new(&token, cli.timeout)?;
    let output = OutputConfig::from_cli(&cli.output, &cli.fields, cli.no_header, cli.quiet);

    match command {
        TaskCommands::List {
            list,
            status,
            assignee,
            tag,
            include_closed,
            order_by,
            reverse,
        } => {
            let mut params = Vec::new();
            if include_closed {
                params.push("include_closed=true".to_string());
            }
            if let Some(statuses) = &status {
                for s in statuses {
                    params.push(format!("statuses[]={}", s));
                }
            }
            if let Some(assignees) = &assignee {
                for a in assignees {
                    params.push(format!("assignees[]={}", a));
                }
            }
            if let Some(tags) = &tag {
                for t in tags {
                    params.push(format!("tags[]={}", t));
                }
            }
            if let Some(ob) = &order_by {
                params.push(format!("order_by={}", ob));
            }
            if reverse {
                params.push("reverse=true".to_string());
            }
            if let Some(page) = cli.page {
                params.push(format!("page={}", page));
            }

            let query = if params.is_empty() {
                String::new()
            } else {
                format!("?{}", params.join("&"))
            };

            if cli.all {
                // Auto-paginate
                let mut all_tasks = Vec::new();
                let mut page = 0u32;
                loop {
                    let mut page_params = params.clone();
                    page_params.push(format!("page={}", page));
                    let page_query = format!("?{}", page_params.join("&"));
                    let resp = client
                        .get(&format!("/v2/list/{}/task{}", list, page_query))
                        .await?;
                    let tasks = resp
                        .get("tasks")
                        .and_then(|t| t.as_array())
                        .cloned()
                        .unwrap_or_default();
                    let is_last = resp
                        .get("last_page")
                        .and_then(|v| v.as_bool())
                        .unwrap_or(true);
                    all_tasks.extend(tasks);
                    if is_last {
                        break;
                    }
                    if let Some(limit) = cli.limit {
                        if all_tasks.len() >= limit {
                            all_tasks.truncate(limit);
                            break;
                        }
                    }
                    page += 1;
                }
                output.print_items(&all_tasks, TASK_FIELDS, "id");
            } else {
                let resp = client
                    .get(&format!("/v2/list/{}/task{}", list, query))
                    .await?;
                let mut tasks = resp
                    .get("tasks")
                    .and_then(|t| t.as_array())
                    .cloned()
                    .unwrap_or_default();
                if let Some(limit) = cli.limit {
                    tasks.truncate(limit);
                }
                output.print_items(&tasks, TASK_FIELDS, "id");
            }
            Ok(())
        }
        TaskCommands::Search {
            space,
            folder,
            list,
            status,
            assignee,
            tag,
        } => {
            let ws_id = resolve_workspace(cli)?;
            let mut params = Vec::new();
            if let Some(s) = &space {
                params.push(format!("space_ids[]={}", s));
            }
            if let Some(f) = &folder {
                params.push(format!("project_ids[]={}", f));
            }
            if let Some(l) = &list {
                params.push(format!("list_ids[]={}", l));
            }
            if let Some(statuses) = &status {
                for s in statuses {
                    params.push(format!("statuses[]={}", s));
                }
            }
            if let Some(assignees) = &assignee {
                for a in assignees {
                    params.push(format!("assignees[]={}", a));
                }
            }
            if let Some(tags) = &tag {
                for t in tags {
                    params.push(format!("tags[]={}", t));
                }
            }
            if let Some(page) = cli.page {
                params.push(format!("page={}", page));
            }
            let query = if params.is_empty() {
                String::new()
            } else {
                format!("?{}", params.join("&"))
            };
            let resp = client
                .get(&format!("/v2/team/{}/task{}", ws_id, query))
                .await?;
            let mut tasks = resp
                .get("tasks")
                .and_then(|t| t.as_array())
                .cloned()
                .unwrap_or_default();
            if let Some(limit) = cli.limit {
                tasks.truncate(limit);
            }
            output.print_items(&tasks, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::Get {
            id,
            subtasks,
            custom_task_id,
        } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let mut params = Vec::new();
            if subtasks {
                params.push("include_subtasks=true".to_string());
            }
            if custom_task_id || task.is_custom {
                params.push("custom_task_ids=true".to_string());
                let ws_id = resolve_workspace(cli)?;
                params.push(format!("team_id={}", ws_id));
            }
            let query = if params.is_empty() {
                String::new()
            } else {
                format!("?{}", params.join("&"))
            };
            let resp = client
                .get(&format!("/v2/task/{}{}", task.id, query))
                .await?;
            output.print_single(&resp, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::Create {
            list,
            name,
            description,
            status,
            priority,
            assignee,
            tag,
            due_date,
            parent,
        } => {
            let mut body = serde_json::json!({ "name": name });
            if let Some(d) = description {
                body["description"] = serde_json::Value::String(d);
            }
            if let Some(s) = status {
                body["status"] = serde_json::Value::String(s);
            }
            if let Some(p) = priority {
                body["priority"] = serde_json::json!(p);
            }
            if let Some(assignees) = assignee {
                let ids: Vec<serde_json::Value> = assignees
                    .iter()
                    .map(|a| serde_json::json!(a.parse::<i64>().unwrap_or(0)))
                    .collect();
                body["assignees"] = serde_json::Value::Array(ids);
            }
            if let Some(tags) = tag {
                body["tags"] = serde_json::json!(tags);
            }
            if let Some(d) = due_date {
                body["due_date"] = serde_json::Value::String(date_to_ms(&d)?);
            }
            if let Some(p) = parent {
                body["parent"] = serde_json::Value::String(p);
            }
            let resp = client
                .post(&format!("/v2/list/{}/task", list), &body)
                .await?;
            output.print_single(&resp, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::Update {
            id,
            name,
            status,
            priority,
            add_assignee,
            rem_assignee,
            description,
        } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let mut body = serde_json::Map::new();
            if let Some(n) = name {
                body.insert("name".into(), serde_json::Value::String(n));
            }
            if let Some(s) = status {
                body.insert("status".into(), serde_json::Value::String(s));
            }
            if let Some(p) = priority {
                body.insert("priority".into(), serde_json::json!(p));
            }
            if let Some(d) = description {
                body.insert("description".into(), serde_json::Value::String(d));
            }
            // Assignee add/remove uses nested object
            if add_assignee.is_some() || rem_assignee.is_some() {
                let mut assignees = serde_json::Map::new();
                if let Some(add) = add_assignee {
                    let ids: Vec<serde_json::Value> = add
                        .iter()
                        .map(|a| serde_json::json!(a.parse::<i64>().unwrap_or(0)))
                        .collect();
                    assignees.insert("add".into(), serde_json::Value::Array(ids));
                }
                if let Some(rem) = rem_assignee {
                    let ids: Vec<serde_json::Value> = rem
                        .iter()
                        .map(|a| serde_json::json!(a.parse::<i64>().unwrap_or(0)))
                        .collect();
                    assignees.insert("rem".into(), serde_json::Value::Array(ids));
                }
                body.insert("assignees".into(), serde_json::Value::Object(assignees));
            }
            let path = if task.is_custom {
                let ws_id = resolve_workspace(cli)?;
                format!(
                    "/v2/task/{}?custom_task_ids=true&team_id={}",
                    task.id, ws_id
                )
            } else {
                format!("/v2/task/{}", task.id)
            };
            let resp = client.put(&path, &serde_json::Value::Object(body)).await?;
            output.print_single(&resp, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::Delete { id } => {
            let task = git::require_task(cli, id.as_deref(), false)?;
            let path = if task.is_custom {
                let ws_id = resolve_workspace(cli)?;
                format!(
                    "/v2/task/{}?custom_task_ids=true&team_id={}",
                    task.id, ws_id
                )
            } else {
                format!("/v2/task/{}", task.id)
            };
            client.delete(&path).await?;
            output.print_message(&format!("Task {} deleted", task.raw));
            Ok(())
        }
        TaskCommands::AddTag {
            task_or_tag,
            tag_name,
        } => {
            let (task, tag_name) = resolve_task_tag(cli, task_or_tag, tag_name)?;
            client
                .post(
                    &format!("/v2/task/{}/tag/{}", task.id, tag_name),
                    &serde_json::json!({}),
                )
                .await?;
            output.print_message(&format!("Tag '{}' added to task {}", tag_name, task.raw));
            Ok(())
        }
        TaskCommands::RemoveTag {
            task_or_tag,
            tag_name,
        } => {
            let (task, tag_name) = resolve_task_tag(cli, task_or_tag, tag_name)?;
            client
                .delete(&format!("/v2/task/{}/tag/{}", task.id, tag_name))
                .await?;
            output.print_message(&format!(
                "Tag '{}' removed from task {}",
                tag_name, task.raw
            ));
            Ok(())
        }
        TaskCommands::AddDep {
            id,
            depends_on,
            dependency_of,
        } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let body = if let Some(other) = depends_on {
                serde_json::json!({ "depends_on": other })
            } else if let Some(other) = dependency_of {
                serde_json::json!({ "dependency_of": other })
            } else {
                return Err(CliError::ClientError {
                    message: "Specify --depends-on or --dependency-of".into(),
                    status: 0,
                });
            };
            client
                .post(&format!("/v2/task/{}/dependency", task.id), &body)
                .await?;
            output.print_message(&format!("Dependency added to task {}", task.raw));
            Ok(())
        }
        TaskCommands::RemoveDep {
            id,
            depends_on,
            dependency_of,
        } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let body = if let Some(other) = depends_on {
                serde_json::json!({ "depends_on": other })
            } else if let Some(other) = dependency_of {
                serde_json::json!({ "dependency_of": other })
            } else {
                return Err(CliError::ClientError {
                    message: "Specify --depends-on or --dependency-of".into(),
                    status: 0,
                });
            };
            client
                .delete_with_body(&format!("/v2/task/{}/dependency", task.id), &body)
                .await?;
            output.print_message(&format!("Dependency removed from task {}", task.raw));
            Ok(())
        }
        TaskCommands::Link { id, target_id } => {
            client
                .post(
                    &format!("/v2/task/{}/link/{}", id, target_id),
                    &serde_json::json!({}),
                )
                .await?;
            output.print_message(&format!("Task {} linked to {}", id, target_id));
            Ok(())
        }
        TaskCommands::Unlink { id, target_id } => {
            client
                .delete(&format!("/v2/task/{}/link/{}", id, target_id))
                .await?;
            output.print_message(&format!("Task {} unlinked from {}", id, target_id));
            Ok(())
        }
        TaskCommands::Move { id, list } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let ws_id = resolve_workspace(cli)?;
            client
                .put(
                    &format!(
                        "/v3/workspaces/{}/tasks/{}/home_list/{}",
                        ws_id, task.id, list
                    ),
                    &serde_json::json!({}),
                )
                .await?;
            output.print_message(&format!("Task {} moved to list {}", task.raw, list));
            Ok(())
        }
        TaskCommands::SetEstimate { id, assignee, time } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let ws_id = resolve_workspace(cli)?;
            let body = serde_json::json!({
                "time_estimates": [{"user_id": assignee, "time_estimate": time}]
            });
            let resp = client
                .patch(
                    &format!(
                        "/v3/workspaces/{}/tasks/{}/time_estimates_by_user",
                        ws_id, task.id
                    ),
                    &body,
                )
                .await?;
            output.print_single(&resp, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::ReplaceEstimates { id, assignee, time } => {
            let task = git::require_task(cli, id.as_deref(), true)?;
            let ws_id = resolve_workspace(cli)?;
            let body = serde_json::json!({
                "time_estimates": [{"user_id": assignee, "time_estimate": time}]
            });
            let resp = client
                .put(
                    &format!(
                        "/v3/workspaces/{}/tasks/{}/time_estimates_by_user",
                        ws_id, task.id
                    ),
                    &body,
                )
                .await?;
            output.print_single(&resp, TASK_FIELDS, "id");
            Ok(())
        }
        TaskCommands::TimeInStatus { ids } => {
            let ids = if ids.is_empty() {
                let task = git::require_task(cli, None, true)?;
                vec![task.id]
            } else {
                ids
            };
            if ids.len() == 1 {
                let resp = client
                    .get(&format!("/v2/task/{}/time_in_status", ids[0]))
                    .await?;
                if cli.output == "json" {
                    println!("{}", serde_json::to_string_pretty(&resp).unwrap());
                } else {
                    // Print status durations
                    if let Some(statuses) = resp.get("current_status").and_then(|v| v.as_object()) {
                        println!(
                            "Current: {} ({}ms)",
                            statuses
                                .get("status")
                                .and_then(|v| v.as_str())
                                .unwrap_or("-"),
                            statuses
                                .get("total_time")
                                .and_then(|v| v.as_object())
                                .and_then(|o| o.get("by_minute"))
                                .and_then(|v| v.as_u64())
                                .unwrap_or(0)
                        );
                    }
                    // Print all statuses
                    if let Some(statuses_arr) =
                        resp.get("status_history").and_then(|v| v.as_array())
                    {
                        for s in statuses_arr {
                            let name = s.get("status").and_then(|v| v.as_str()).unwrap_or("-");
                            let time = s
                                .get("total_time")
                                .and_then(|v| v.as_object())
                                .and_then(|o| o.get("by_minute"))
                                .and_then(|v| v.as_u64())
                                .unwrap_or(0);
                            println!("  {}{}ms", name, time);
                        }
                    }
                }
            } else {
                // Bulk mode
                let task_ids = ids.join(",");
                let resp = client
                    .get(&format!(
                        "/v2/task/bulk_time_in_status/task_ids?task_ids={}",
                        task_ids
                    ))
                    .await?;
                if cli.output == "json" {
                    println!("{}", serde_json::to_string_pretty(&resp).unwrap());
                } else {
                    // Print per-task summary
                    if let Some(obj) = resp.as_object() {
                        for (task_id, data) in obj {
                            let current = data
                                .get("current_status")
                                .and_then(|v| v.get("status"))
                                .and_then(|v| v.as_str())
                                .unwrap_or("-");
                            println!("{}: {}", task_id, current);
                        }
                    }
                }
            }
            Ok(())
        }
    }
}

/// Disambiguate `add-tag` / `remove-tag` positionals:
/// - Two args: `<task_id> <tag_name>` — explicit ID, parsed through `parse_task_id`.
/// - One arg: `<tag_name>` — task auto-detected from branch.
fn resolve_task_tag(
    cli: &Cli,
    task_or_tag: String,
    tag_name: Option<String>,
) -> Result<(git::ResolvedTask, String), CliError> {
    match tag_name {
        Some(tag) => Ok((git::parse_task_id(&task_or_tag), tag)),
        None => {
            let task = git::require_task(cli, None, true)?;
            Ok((task, task_or_tag))
        }
    }
}

fn date_to_ms(date_str: &str) -> Result<String, CliError> {
    let naive = chrono::NaiveDate::parse_from_str(date_str, "%Y-%m-%d").map_err(|_| {
        CliError::ClientError {
            message: format!("Invalid date '{}'. Use YYYY-MM-DD format.", date_str),
            status: 0,
        }
    })?;
    let dt = naive.and_hms_opt(0, 0, 0).unwrap().and_utc();
    Ok((dt.timestamp_millis()).to_string())
}