git-parsec 0.3.0

Git worktree lifecycle manager — ticket to PR in one command. Parallel AI agent workflows with Jira & GitHub Issues integration.
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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
use colored::Colorize;
use tabled::settings::Style;
use tabled::{Table, Tabled};

use super::BoardTicketDisplay;
use crate::config::ParsecConfig;
use crate::conflict::FileConflict;
use crate::oplog::OpEntry;
use crate::tracker::jira::{InboxTicket, SprintInfo};
use crate::tracker::Ticket as TrackerTicket;
use crate::worktree::{ShipResult, Workspace, WorkspaceStatus};

// ---------------------------------------------------------------------------
// Table row types
// ---------------------------------------------------------------------------

#[derive(Tabled)]
struct ConflictRow {
    #[tabled(rename = "File")]
    file: String,
    #[tabled(rename = "Worktrees")]
    worktrees: String,
}

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

fn status_label(status: &WorkspaceStatus) -> String {
    match status {
        WorkspaceStatus::Active => "active".green().to_string(),
        WorkspaceStatus::Shipped => "shipped".yellow().to_string(),
        WorkspaceStatus::Merged => "merged".blue().to_string(),
    }
}

// ---------------------------------------------------------------------------
// Public print functions
// ---------------------------------------------------------------------------

pub fn print_start(workspace: &Workspace) {
    let msg = format!(
        "Created workspace for {} at {}",
        workspace.ticket.bold(),
        workspace.path.display()
    );
    println!("{}", msg.green());
    if let Some(title) = &workspace.ticket_title {
        println!("  {}", title.dimmed());
    }
    // Shell integration hint
    eprintln!(
        "\n  {} cd $(parsec switch {})",
        "Tip:".bold().cyan(),
        workspace.ticket
    );
}

pub fn print_adopt(workspace: &Workspace) {
    let msg = format!(
        "Adopted branch '{}' as {} at {}",
        workspace.branch,
        workspace.ticket.bold(),
        workspace.path.display()
    );
    println!("{}", msg.green());
    if let Some(title) = &workspace.ticket_title {
        println!("  {}", title.dimmed());
    }
    // Shell integration hint
    eprintln!(
        "\n  {} cd $(parsec switch {})",
        "Tip:".bold().cyan(),
        workspace.ticket
    );
}

pub fn print_list(
    workspaces: &[Workspace],
    pr_map: &std::collections::HashMap<String, (u64, String)>,
) {
    if workspaces.is_empty() {
        println!("{}", "No active workspaces.".dimmed());
        return;
    }

    #[derive(Tabled)]
    struct WorkspaceRowWithPr {
        #[tabled(rename = "Ticket")]
        ticket: String,
        #[tabled(rename = "Branch")]
        branch: String,
        #[tabled(rename = "Status")]
        status: String,
        #[tabled(rename = "PR")]
        pr: String,
        #[tabled(rename = "Created")]
        created: String,
        #[tabled(rename = "Path")]
        path: String,
    }

    let rows: Vec<WorkspaceRowWithPr> = workspaces
        .iter()
        .map(|ws| {
            let pr = if let Some((num, state)) = pr_map.get(&ws.ticket) {
                let label = format!("#{}", num);
                match state.as_str() {
                    "open" => label.green().to_string(),
                    "closed" => label.red().to_string(),
                    "merged" => label.cyan().to_string(),
                    _ => label,
                }
            } else {
                "-".dimmed().to_string()
            };
            WorkspaceRowWithPr {
                ticket: ws.ticket.clone(),
                branch: ws.branch.clone(),
                status: status_label(&ws.status),
                pr,
                created: ws.created_at.format("%Y-%m-%d %H:%M").to_string(),
                path: ws.path.display().to_string(),
            }
        })
        .collect();
    let table = Table::new(rows).with(Style::modern()).to_string();
    println!("{}", table);
}

pub fn print_status(workspaces: &[Workspace]) {
    if workspaces.is_empty() {
        println!("{}", "No workspaces found.".dimmed());
        return;
    }
    for ws in workspaces {
        println!("{}", "".repeat(50).dimmed());
        println!("  {} {}", "Ticket:".bold(), ws.ticket);
        if let Some(title) = &ws.ticket_title {
            println!("  {} {}", "Title:".bold(), title);
        }
        println!("  {} {}", "Branch:".bold(), ws.branch);
        println!("  {} {}", "Base:".bold(), ws.base_branch);
        println!("  {} {}", "Status:".bold(), status_label(&ws.status));
        println!(
            "  {} {}",
            "Created:".bold(),
            ws.created_at.format("%Y-%m-%d %H:%M UTC")
        );
        println!("  {} {}", "Path:".bold(), ws.path.display());
    }
    println!("{}", "".repeat(50).dimmed());
}

pub fn print_ship(result: &ShipResult) {
    if result.pr_url.is_some() || result.cleaned_up {
        println!("{}", format!("Shipped {}!", result.ticket).green().bold());
    } else {
        println!(
            "{}",
            format!("Shipped {} (partial — PR failed)", result.ticket)
                .yellow()
                .bold()
        );
    }
    if let Some(url) = &result.pr_url {
        println!("  {} {}", "PR:".bold(), url.cyan());
    }
    if result.cleaned_up {
        println!("  {}", "Workspace cleaned up.".dimmed());
    }
}

pub fn print_clean(removed: &[Workspace], dry_run: bool) {
    if removed.is_empty() {
        if dry_run {
            println!("{}", "Nothing to remove.".dimmed());
        } else {
            println!("{}", "No worktrees were removed.".dimmed());
        }
        return;
    }
    let verb = if dry_run { "Would remove" } else { "Removed" };
    println!("{} {} worktree(s):", verb.bold(), removed.len());
    for ws in removed {
        println!("  {} {}", "-".dimmed(), ws.ticket.yellow());
    }
}

pub fn print_conflicts(conflicts: &[FileConflict]) {
    if conflicts.is_empty() {
        println!("{}", "No conflicts detected.".green());
        return;
    }
    println!(
        "{}",
        format!("Found {} conflict(s):", conflicts.len())
            .yellow()
            .bold()
    );
    let rows: Vec<ConflictRow> = conflicts
        .iter()
        .map(|c| ConflictRow {
            file: c.file.clone(),
            worktrees: c.worktrees.join(", "),
        })
        .collect();
    let table = Table::new(rows).with(Style::modern()).to_string();
    println!("{}", table);
}

pub fn print_switch(workspace: &Workspace) {
    // Intentionally plain — designed for `cd $(parsec switch X)`
    print!("{}", workspace.path.display());
}

pub fn print_config_init() {
    println!("{}", "Configuration saved!".green().bold());
}

pub fn print_log(entries: &[&OpEntry]) {
    if entries.is_empty() {
        println!("{}", "No operations recorded.".dimmed());
        return;
    }

    #[derive(Tabled)]
    struct LogRow {
        #[tabled(rename = "#")]
        id: u64,
        #[tabled(rename = "Op")]
        op: String,
        #[tabled(rename = "Ticket")]
        ticket: String,
        #[tabled(rename = "Detail")]
        detail: String,
        #[tabled(rename = "Time")]
        time: String,
    }

    let rows: Vec<LogRow> = entries
        .iter()
        .rev()
        .map(|e| LogRow {
            id: e.id,
            op: match &e.op {
                crate::oplog::OpKind::Start => "start".green().to_string(),
                crate::oplog::OpKind::Adopt => "adopt".cyan().to_string(),
                crate::oplog::OpKind::Ship => "ship".yellow().to_string(),
                crate::oplog::OpKind::Clean => "clean".red().to_string(),
                crate::oplog::OpKind::Undo => "undo".magenta().to_string(),
            },
            ticket: e.ticket.clone().unwrap_or_else(|| "-".to_string()),
            detail: e.detail.clone(),
            time: e.timestamp.format("%Y-%m-%d %H:%M").to_string(),
        })
        .collect();

    let table = Table::new(rows).with(Style::modern()).to_string();
    println!("{}", table);
}

pub fn print_undo(entry: &OpEntry) {
    let ticket_str = entry.ticket.as_deref().unwrap_or("?");
    let msg = format!("Undid {} for {}", entry.op, ticket_str);
    println!("{}", msg.green().bold());

    match &entry.op {
        crate::oplog::OpKind::Start | crate::oplog::OpKind::Adopt => {
            println!("  {}", "Worktree removed.".dimmed());
        }
        crate::oplog::OpKind::Ship | crate::oplog::OpKind::Clean => {
            if let Some(info) = &entry.undo_info {
                if let Some(path) = &info.path {
                    println!("  {} {}", "Restored at:".bold(), path.display());
                }
            }
            println!("  {}", "Workspace restored.".dimmed());
        }
        _ => {}
    }
}

pub fn print_undo_preview(entry: &OpEntry) {
    let ticket_str = entry.ticket.as_deref().unwrap_or("?");
    println!(
        "{}",
        format!("Would undo: {} {}", entry.op, ticket_str)
            .yellow()
            .bold()
    );

    match &entry.op {
        crate::oplog::OpKind::Start | crate::oplog::OpKind::Adopt => {
            if let Some(info) = &entry.undo_info {
                if let Some(path) = &info.path {
                    println!("  Would remove worktree at {}", path.display());
                }
                if let Some(branch) = &info.branch {
                    println!("  Would delete branch '{}'", branch);
                }
            }
        }
        crate::oplog::OpKind::Ship | crate::oplog::OpKind::Clean => {
            if let Some(info) = &entry.undo_info {
                if let Some(branch) = &info.branch {
                    println!("  Would restore worktree for branch '{}'", branch);
                }
            }
        }
        _ => {
            println!("  {}", "This operation cannot be undone.".red());
        }
    }
}

pub fn print_sync(synced: &[String], failed: &[(String, String)], strategy: &str) {
    if !synced.is_empty() {
        println!(
            "{} {} {} worktree(s):",
            "".green(),
            strategy.bold(),
            synced.len()
        );
        for ticket in synced {
            println!("  - {}", ticket);
        }
    }
    if !failed.is_empty() {
        println!(
            "{} Failed to {} {} worktree(s):",
            "".red(),
            strategy,
            failed.len()
        );
        for (ticket, reason) in failed {
            println!("  - {}: {}", ticket, reason.red());
        }
    }
    if synced.is_empty() && failed.is_empty() {
        println!("Nothing to sync.");
    }
}

pub fn print_pr_status(statuses: &[(String, crate::github::PrStatus)]) {
    use tabled::{Table, Tabled};

    #[derive(Tabled)]
    struct Row {
        #[tabled(rename = "Ticket")]
        ticket: String,
        #[tabled(rename = "PR")]
        pr: String,
        #[tabled(rename = "State")]
        state: String,
        #[tabled(rename = "CI")]
        ci: String,
        #[tabled(rename = "Reviews")]
        reviews: String,
    }

    let rows: Vec<Row> = statuses
        .iter()
        .map(|(ticket, s)| {
            let ci = match s.ci_status.as_str() {
                "success" => "✓ passed".green().to_string(),
                "failure" | "error" => "✗ failed".red().to_string(),
                "pending" => "● pending".yellow().to_string(),
                _ => s.ci_status.clone(),
            };
            let reviews = match s.review_status.as_str() {
                "approved" => "✓ approved".green().to_string(),
                "changes_requested" => "✗ changes requested".red().to_string(),
                "pending" => "● pending".yellow().to_string(),
                _ => s.review_status.clone(),
            };
            let state = match s.state.as_str() {
                "open" => "open".green().to_string(),
                "closed" => "closed".red().to_string(),
                "merged" => "merged".cyan().to_string(),
                _ => s.state.clone(),
            };
            Row {
                ticket: ticket.clone(),
                pr: format!("#{}", s.number),
                state,
                ci,
                reviews,
            }
        })
        .collect();

    if rows.is_empty() {
        println!("No shipped PRs found.");
        return;
    }

    let table = Table::new(rows)
        .with(tabled::settings::Style::modern())
        .to_string();
    println!("{table}");
}

pub fn print_merge(
    ticket: &str,
    pr_number: u64,
    result: &crate::github::MergeResult,
    method: &str,
) {
    println!(
        "{}",
        format!("Merged PR #{} for {}!", pr_number, ticket)
            .green()
            .bold()
    );
    println!("  {} {}", "Method:".bold(), method);
    println!("  {} {}", "SHA:".bold(), result.sha.dimmed());
    if !result.message.is_empty() {
        println!("  {} {}", "Message:".bold(), result.message);
    }
}

pub fn print_ci_status(statuses: &[(String, crate::github::CiStatus)]) {
    use tabled::{Table, Tabled};

    for (ticket, ci) in statuses {
        println!(
            "{} {} (PR #{}, {})",
            "CI for".bold(),
            ticket.bold().cyan(),
            ci.pr_number,
            ci.head_sha[..7].dimmed()
        );

        if ci.checks.is_empty() {
            println!("  {}", "No checks found.".dimmed());
            println!();
            continue;
        }

        #[derive(Tabled)]
        struct CheckRow {
            #[tabled(rename = "Check")]
            name: String,
            #[tabled(rename = "Status")]
            status: String,
            #[tabled(rename = "Duration")]
            duration: String,
        }

        let rows: Vec<CheckRow> = ci
            .checks
            .iter()
            .map(|c| {
                let status = match (c.status.as_str(), c.conclusion.as_deref()) {
                    (_, Some("success")) => "✓ passed".green().to_string(),
                    (_, Some("failure")) => "✗ failed".red().to_string(),
                    (_, Some("skipped")) => "- skipped".dimmed().to_string(),
                    ("in_progress", _) => "● running".yellow().to_string(),
                    ("queued", _) => "○ queued".dimmed().to_string(),
                    _ => c.status.clone(),
                };
                let duration = match (&c.started_at, &c.completed_at) {
                    (Some(start), Some(end)) => {
                        if let (Ok(s), Ok(e)) = (
                            chrono::DateTime::parse_from_rfc3339(start),
                            chrono::DateTime::parse_from_rfc3339(end),
                        ) {
                            let secs = (e - s).num_seconds();
                            if secs >= 60 {
                                format!("{}m {}s", secs / 60, secs % 60)
                            } else {
                                format!("{}s", secs)
                            }
                        } else {
                            "-".to_string()
                        }
                    }
                    (Some(_), None) => "running...".to_string(),
                    _ => "-".to_string(),
                };
                CheckRow {
                    name: c.name.clone(),
                    status,
                    duration,
                }
            })
            .collect();

        let table = Table::new(rows)
            .with(tabled::settings::Style::modern())
            .to_string();
        println!("{table}");

        // Summary line
        let passed = ci
            .checks
            .iter()
            .filter(|c| c.conclusion.as_deref() == Some("success"))
            .count();
        let failed = ci
            .checks
            .iter()
            .filter(|c| c.conclusion.as_deref() == Some("failure"))
            .count();
        let running = ci
            .checks
            .iter()
            .filter(|c| c.status == "in_progress")
            .count();
        let queued = ci.checks.iter().filter(|c| c.status == "queued").count();
        let total = ci.checks.len();

        let mut parts = Vec::new();
        if passed > 0 {
            parts.push(format!("{passed} passed").green().to_string());
        }
        if failed > 0 {
            parts.push(format!("{failed} failed").red().to_string());
        }
        if running > 0 {
            parts.push(format!("{running} running").yellow().to_string());
        }
        if queued > 0 {
            parts.push(format!("{queued} queued"));
        }

        let overall_icon = match ci.overall.as_str() {
            "passing" => "".green().to_string(),
            "failing" => "".red().to_string(),
            _ => "".yellow().to_string(),
        };

        println!(
            "{} CI: {}/{}{}",
            overall_icon,
            passed,
            total,
            parts.join(", ")
        );
        println!();
    }
}

pub fn print_diff_names(files: &[String], ticket: &str) {
    println!(
        "{} {} ({} files):",
        "Changed files for".bold(),
        ticket.bold().cyan(),
        files.len()
    );
    for f in files {
        println!("  {}", f);
    }
}

pub fn print_diff_stat(stat: &str, ticket: &str) {
    println!("{} {}:", "Diff stat for".bold(), ticket.bold().cyan());
    print!("{}", stat);
}

pub fn print_stack(workspaces: &[Workspace]) {
    use std::collections::HashMap;

    // Build parent -> children map
    let mut children_map: HashMap<&str, Vec<&Workspace>> = HashMap::new();
    let mut roots = Vec::new();

    for ws in workspaces {
        if let Some(parent) = &ws.parent_ticket {
            children_map.entry(parent.as_str()).or_default().push(ws);
        } else if workspaces
            .iter()
            .any(|other| other.parent_ticket.as_deref() == Some(&ws.ticket))
        {
            roots.push(ws);
        }
    }

    println!("{}", "Stack dependency graph:".bold());

    fn print_tree(
        ws: &Workspace,
        children_map: &HashMap<&str, Vec<&Workspace>>,
        prefix: &str,
        is_last: bool,
    ) {
        use colored::Colorize;
        let connector = if prefix.is_empty() {
            ""
        } else if is_last {
            "└── "
        } else {
            "├── "
        };
        let title = ws.ticket_title.as_deref().unwrap_or("");
        println!(
            "{}{}{}  {}",
            prefix,
            connector,
            ws.ticket.bold().cyan(),
            title.dimmed()
        );

        let child_prefix = if prefix.is_empty() {
            String::new()
        } else if is_last {
            format!("{}    ", prefix)
        } else {
            format!("{}", prefix)
        };

        if let Some(children) = children_map.get(ws.ticket.as_str()) {
            for (i, child) in children.iter().enumerate() {
                print_tree(child, children_map, &child_prefix, i == children.len() - 1);
            }
        }
    }

    for (i, root) in roots.iter().enumerate() {
        if i > 0 {
            println!();
        }
        print_tree(root, &children_map, "", true);
    }
}

pub fn print_board(sprint: Option<&SprintInfo>, columns: &[(String, Vec<BoardTicketDisplay>)]) {
    // Sprint header: show dates in compact form
    if let Some(s) = sprint {
        let start = s
            .start_date
            .as_deref()
            .and_then(|d| d.get(..10))
            .unwrap_or("");
        let end = s
            .end_date
            .as_deref()
            .and_then(|d| d.get(..10))
            .unwrap_or("");
        // Use short date format: strip leading "20" → "26.04.06"
        let fmt_date = |d: &str| -> String {
            if d.len() >= 10 {
                let without_century = &d[2..];
                without_century.replace('-', ".")
            } else {
                d.to_string()
            }
        };
        if !start.is_empty() && !end.is_empty() {
            println!(
                "{}",
                format!("{} ~ {}", fmt_date(start), fmt_date(end)).dimmed()
            );
        }
        println!();
    }

    if columns.is_empty() {
        println!("{}", "No tickets in sprint.".dimmed());
        return;
    }

    for (i, (status, tickets)) in columns.iter().enumerate() {
        if i > 0 {
            println!();
        }
        // Status header: bold name + dimmed count
        println!(
            "{} {}",
            status.bold(),
            format!("({})", tickets.len()).dimmed()
        );

        for ticket in tickets {
            let indicator = if ticket.has_worktree {
                format!(" {}", "[wt]".green())
            } else if ticket.has_pr {
                format!(" {}", "[pr]".blue())
            } else {
                "     ".to_string()
            };
            println!("  {}{}  {}", ticket.key, indicator, ticket.summary.dimmed());
        }
    }
}

pub fn print_ticket(ticket: &TrackerTicket) {
    println!("{}: {}", ticket.id.yellow().bold(), ticket.title.bold());
    if let Some(ref status) = ticket.status {
        println!("  {} {}", "Status:".bold(), status);
    }
    if let Some(ref assignee) = ticket.assignee {
        println!("  {} {}", "Assignee:".bold(), assignee);
    }
    if let Some(ref url) = ticket.url {
        println!("  {} {}", "URL:".bold(), url.cyan());
    }
}

fn mask_token(token: &str) -> String {
    if token.len() <= 8 {
        return "*".repeat(token.len());
    }
    let prefix = &token[..4];
    let suffix = &token[token.len() - 4..];
    format!("{}****...{}", prefix, suffix)
}

pub fn print_comment(ticket_id: &str) {
    println!("{} Comment posted on {}", "".green(), ticket_id.bold());
}

pub fn print_inbox(tickets: &[InboxTicket]) {
    if tickets.is_empty() {
        println!(
            "{}",
            "No assigned tickets without active worktrees.".dimmed()
        );
        return;
    }

    #[derive(Tabled)]
    struct InboxRow {
        #[tabled(rename = "Ticket")]
        ticket: String,
        #[tabled(rename = "Title")]
        title: String,
        #[tabled(rename = "Priority")]
        priority: String,
        #[tabled(rename = "Status")]
        status: String,
    }

    let rows: Vec<InboxRow> = tickets
        .iter()
        .map(|t| {
            let priority = match t.priority.as_str() {
                "Highest" | "Critical" => t.priority.clone().red().bold().to_string(),
                "High" => t.priority.clone().red().to_string(),
                "Medium" => t.priority.clone().yellow().to_string(),
                "Low" => t.priority.clone().green().to_string(),
                "Lowest" => t.priority.clone().dimmed().to_string(),
                _ => t.priority.clone(),
            };
            // Truncate long titles for table readability
            let title = if t.summary.len() > 60 {
                format!("{}...", &t.summary[..57])
            } else {
                t.summary.clone()
            };
            InboxRow {
                ticket: t.key.clone(),
                title,
                priority,
                status: t.status.clone(),
            }
        })
        .collect();

    let table = Table::new(rows).with(Style::modern()).to_string();
    println!("{}", table);
}

pub fn print_config_show(config: &ParsecConfig) {
    println!("{}", "[workspace]".bold());
    println!("  layout          = {}", config.workspace.layout);
    println!("  base_dir        = {}", config.workspace.base_dir);
    println!("  branch_prefix   = {}", config.workspace.branch_prefix);
    if let Some(ref default_base) = config.workspace.default_base {
        println!("  default_base    = {}", default_base);
    }
    println!();
    println!("{}", "[tracker]".bold());
    println!("  provider       = {}", config.tracker.provider);
    if let Some(jira) = &config.tracker.jira {
        println!("  jira.base_url  = {}", jira.base_url);
        if let Some(email) = &jira.email {
            println!("  jira.email     = {}", email);
        }
    }
    if let Some(gitlab) = &config.tracker.gitlab {
        println!("  gitlab.base_url = {}", gitlab.base_url);
    }
    println!("  comment_on_ship = {}", config.tracker.comment_on_ship);
    println!();
    println!("{}", "[ship]".bold());
    println!("  auto_pr         = {}", config.ship.auto_pr);
    println!("  auto_cleanup    = {}", config.ship.auto_cleanup);
    println!("  draft           = {}", config.ship.draft);
    if !config.github.is_empty() {
        println!();
        let mut hosts: Vec<&String> = config.github.keys().collect();
        hosts.sort();
        for host in hosts {
            let host_cfg = &config.github[host];
            println!("{}", format!("[github.\"{}\"]", host).bold());
            if let Some(ref token) = host_cfg.token {
                println!("  token           = {}", mask_token(token).dimmed());
            }
        }
    }
    if !config.hooks.post_create.is_empty() {
        println!();
        println!("{}", "[hooks]".bold());
        for cmd in &config.hooks.post_create {
            println!("  post_create     = {}", cmd);
        }
    }
    if !config.repos.is_empty() {
        println!();
        let mut repo_keys: Vec<&String> = config.repos.keys().collect();
        repo_keys.sort();
        for key in repo_keys {
            let repo_cfg = &config.repos[key];
            if let Some(ref tracker) = repo_cfg.tracker {
                println!("{}", format!("[repos.\"{}\".tracker]", key).bold());
                if let Some(ref provider) = tracker.provider {
                    println!("  provider       = {}", provider);
                }
                if let Some(ref jira) = tracker.jira {
                    println!("  jira.base_url  = {}", jira.base_url);
                }
                if let Some(ref gitlab) = tracker.gitlab {
                    println!("  gitlab.base_url = {}", gitlab.base_url);
                }
            }
        }
    }
}