gitstack 5.3.0

Git history viewer with insights - Author stats, file heatmap, code ownership
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
//! Workflow overlay renderers (PR creation, Review queue)

use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, List, ListItem, Paragraph};
use ratatui::Frame;

use crate::app::App;

/// Render the PR creation overlay
pub(crate) fn render_pr_create_overlay(frame: &mut Frame, app: &App) {
    let area = centered_rect(60, 60, frame.area());
    frame.render_widget(Clear, area);

    let block = Block::default()
        .title(" Create Pull Request ")
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Cyan));

    let inner = block.inner(area);
    frame.render_widget(block, area);

    let chunks = Layout::vertical([
        Constraint::Length(3), // Title
        Constraint::Length(1), // Separator
        Constraint::Min(5),    // Body
        Constraint::Length(3), // Actions
    ])
    .split(inner);

    // Title input
    let title_style = if !app.pr_create_state.editing_body {
        Style::default().fg(Color::Yellow)
    } else {
        Style::default().fg(Color::White)
    };
    let title_block = Block::default()
        .title(" Title ")
        .borders(Borders::ALL)
        .border_style(title_style);
    let title_text = Paragraph::new(app.pr_create_state.title.as_str()).block(title_block);
    frame.render_widget(title_text, chunks[0]);

    // Body
    let body_style = if app.pr_create_state.editing_body {
        Style::default().fg(Color::Yellow)
    } else {
        Style::default().fg(Color::White)
    };
    let body_block = Block::default()
        .title(" Body ")
        .borders(Borders::ALL)
        .border_style(body_style);
    let body_text = Paragraph::new(app.pr_create_state.body.as_str())
        .block(body_block)
        .wrap(ratatui::widgets::Wrap { trim: false });
    frame.render_widget(body_text, chunks[2]);

    // Actions
    let gh_status = if app.pr_create_state.gh_available {
        Span::styled("gh: ✓", Style::default().fg(Color::Green))
    } else {
        Span::styled("gh: ✗", Style::default().fg(Color::Red))
    };
    let actions = Line::from(vec![
        Span::raw(" Tab: switch field | Enter: create | Esc: cancel | "),
        gh_status,
    ]);
    let actions_widget = Paragraph::new(actions).alignment(Alignment::Center);
    frame.render_widget(actions_widget, chunks[3]);
}

/// Render the review queue overlay
pub(crate) fn render_review_queue_overlay(frame: &mut Frame, app: &App) {
    let area = centered_rect(70, 70, frame.area());
    frame.render_widget(Clear, area);

    let block = Block::default()
        .title(" Review Queue ")
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Magenta));

    let inner = block.inner(area);
    frame.render_widget(block, area);

    let chunks = Layout::vertical([
        Constraint::Min(5),    // List
        Constraint::Length(3), // Actions
    ])
    .split(inner);

    // Review items list
    let items: Vec<ListItem> = app
        .review_queue_view
        .cache
        .as_ref()
        .map(|queue| {
            queue
                .items
                .iter()
                .enumerate()
                .map(|(i, item)| {
                    let status_icon = match item.status {
                        crate::review_queue::ReviewStatus::Pending => "",
                        crate::review_queue::ReviewStatus::Approved => "",
                        crate::review_queue::ReviewStatus::Rejected => "",
                    };
                    let style = if i == app.review_queue_view.nav.selected_index {
                        Style::default()
                            .fg(Color::Yellow)
                            .add_modifier(Modifier::BOLD)
                    } else {
                        Style::default()
                    };
                    ListItem::new(Line::from(vec![
                        Span::styled(
                            format!(" {} ", status_icon),
                            Style::default().fg(match item.status {
                                crate::review_queue::ReviewStatus::Pending => Color::Yellow,
                                crate::review_queue::ReviewStatus::Approved => Color::Green,
                                crate::review_queue::ReviewStatus::Rejected => Color::Red,
                            }),
                        ),
                        Span::styled(
                            format!("[{}] ", &item.commit_hash[..7.min(item.commit_hash.len())]),
                            Style::default().fg(Color::Cyan),
                        ),
                        Span::styled(
                            item.review_points.first().cloned().unwrap_or_default(),
                            style,
                        ),
                    ]))
                })
                .collect()
        })
        .unwrap_or_default();

    if items.is_empty() {
        let empty = Paragraph::new(" No review items").style(Style::default().fg(Color::DarkGray));
        frame.render_widget(empty, chunks[0]);
    } else {
        let list = List::new(items);
        frame.render_widget(list, chunks[0]);
    }

    // Actions
    let actions = Paragraph::new(" j/k: navigate | a: approve | x: reject | Esc: close")
        .alignment(Alignment::Center)
        .style(Style::default().fg(Color::DarkGray));
    frame.render_widget(actions, chunks[1]);
}

/// Render the review pack view overlay
pub(crate) fn render_review_pack_view_overlay(frame: &mut Frame, app: &App) {
    let area = centered_rect(80, 80, frame.area());
    frame.render_widget(Clear, area);

    let block = Block::default()
        .title(" Review Pack ")
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Cyan));

    let inner = block.inner(area);
    frame.render_widget(block, area);

    let chunks = Layout::vertical([
        Constraint::Length(4), // Summary
        Constraint::Min(5),    // Content
        Constraint::Length(2), // Actions
    ])
    .split(inner);

    if let Some(ref pack) = app.review_pack_view.cache {
        // Summary section
        let verdict_str = app
            .review_pack_view
            .verdict
            .as_ref()
            .and_then(|v| v.get("verdict"))
            .and_then(|v| v.as_str())
            .unwrap_or("unknown");
        let verdict_color = match verdict_str {
            "low_risk" => Color::Green,
            "needs_review" => Color::Yellow,
            "high_risk" => Color::Red,
            _ => Color::White,
        };

        let risk_bar_len = (pack.risk_score * 20.0).round() as usize;
        let risk_bar = format!(
            "[{}{}]",
            "#".repeat(risk_bar_len),
            "-".repeat(20 - risk_bar_len)
        );

        let summary_lines = vec![
            Line::from(vec![
                Span::styled(" Repo: ", Style::default().fg(Color::DarkGray)),
                Span::raw(&pack.repo),
                Span::raw("  "),
                Span::styled("Branch: ", Style::default().fg(Color::DarkGray)),
                Span::raw(&pack.branch),
                Span::raw("  "),
                Span::styled("HEAD: ", Style::default().fg(Color::DarkGray)),
                Span::styled(&pack.head, Style::default().fg(Color::Cyan)),
            ]),
            Line::from(vec![
                Span::styled(" Risk: ", Style::default().fg(Color::DarkGray)),
                Span::styled(
                    format!("{:.2}", pack.risk_score),
                    Style::default().fg(verdict_color),
                ),
                Span::raw(" "),
                Span::styled(risk_bar, Style::default().fg(verdict_color)),
                Span::raw("  "),
                Span::styled("Conf: ", Style::default().fg(Color::DarkGray)),
                Span::raw(format!("{:.2}", pack.confidence)),
                Span::raw("  "),
                Span::styled("Verdict: ", Style::default().fg(Color::DarkGray)),
                Span::styled(
                    verdict_str,
                    Style::default()
                        .fg(verdict_color)
                        .add_modifier(Modifier::BOLD),
                ),
            ]),
            Line::from(vec![
                Span::styled(" Summary: ", Style::default().fg(Color::DarkGray)),
                Span::raw(&pack.summary),
            ]),
        ];
        let summary = Paragraph::new(summary_lines);
        frame.render_widget(summary, chunks[0]);

        // Content section: risks, test gaps, actions, owners
        let mut items: Vec<ListItem> = Vec::new();
        let mut current_idx = 0;

        // Top Risks
        if !pack.top_risks.is_empty() {
            items.push(ListItem::new(Line::from(Span::styled(
                "── Top Risks ──",
                Style::default()
                    .fg(Color::Yellow)
                    .add_modifier(Modifier::BOLD),
            ))));
            current_idx += 1;
            for risk in &pack.top_risks {
                let sev_color = match risk.severity.as_str() {
                    "high" => Color::Red,
                    "medium" => Color::Yellow,
                    _ => Color::Green,
                };
                let selected = current_idx == app.review_pack_view.nav.selected_index + 1;
                let style = if selected {
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD)
                } else {
                    Style::default()
                };
                items.push(ListItem::new(Line::from(vec![
                    Span::styled(
                        format!(" [{}] ", risk.severity.to_uppercase()),
                        Style::default().fg(sev_color).add_modifier(Modifier::BOLD),
                    ),
                    Span::styled(&risk.title, style),
                    Span::styled(
                        format!(" - {}", risk.details),
                        Style::default().fg(Color::DarkGray),
                    ),
                ])));
                current_idx += 1;
            }
        }

        // Test Gaps
        if !pack.test_gaps.is_empty() {
            items.push(ListItem::new(Line::from(Span::styled(
                "── Test Gaps ──",
                Style::default()
                    .fg(Color::Magenta)
                    .add_modifier(Modifier::BOLD),
            ))));
            current_idx += 1;
            for gap in &pack.test_gaps {
                let selected = current_idx == app.review_pack_view.nav.selected_index + 1;
                let style = if selected {
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD)
                } else {
                    Style::default().fg(Color::Magenta)
                };
                items.push(ListItem::new(Line::from(Span::styled(
                    format!("  - {}", gap),
                    style,
                ))));
                current_idx += 1;
            }
        }

        // Recommended Actions
        if !pack.recommended_actions.is_empty() {
            items.push(ListItem::new(Line::from(Span::styled(
                "── Recommended Actions ──",
                Style::default()
                    .fg(Color::Green)
                    .add_modifier(Modifier::BOLD),
            ))));
            current_idx += 1;
            for action in &pack.recommended_actions {
                let pri_color = match action.priority.as_str() {
                    "high" => Color::Red,
                    "medium" => Color::Yellow,
                    _ => Color::Green,
                };
                let selected = current_idx == app.review_pack_view.nav.selected_index + 1;
                let style = if selected {
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD)
                } else {
                    Style::default()
                };
                items.push(ListItem::new(Line::from(vec![
                    Span::styled(
                        format!(" [{}] ", action.priority),
                        Style::default().fg(pri_color),
                    ),
                    Span::styled(&action.title, style),
                    Span::styled(
                        format!(" - {}", action.reason),
                        Style::default().fg(Color::DarkGray),
                    ),
                ])));
                current_idx += 1;
            }
        }

        // Owner Candidates
        if !pack.owner_candidates.is_empty() {
            items.push(ListItem::new(Line::from(Span::styled(
                "── Owner Candidates ──",
                Style::default()
                    .fg(Color::Blue)
                    .add_modifier(Modifier::BOLD),
            ))));
            for candidate in &pack.owner_candidates {
                items.push(ListItem::new(Line::from(vec![
                    Span::styled("  ", Style::default()),
                    Span::styled(&candidate.author, Style::default().fg(Color::Cyan)),
                    Span::styled(
                        format!(" ({:.0}%) ", candidate.ownership_percent * 100.0),
                        Style::default().fg(Color::DarkGray),
                    ),
                    Span::raw(&candidate.path),
                ])));
            }
        }

        let list = List::new(items);
        frame.render_widget(list, chunks[1]);
    } else {
        let empty =
            Paragraph::new(" No review pack data").style(Style::default().fg(Color::DarkGray));
        frame.render_widget(empty, chunks[1]);
    }

    // Actions footer
    let actions = Paragraph::new(" j/k: scroll | Esc/q: close")
        .alignment(Alignment::Center)
        .style(Style::default().fg(Color::DarkGray));
    frame.render_widget(actions, chunks[2]);
}

/// Render the next actions view overlay
pub(crate) fn render_next_actions_view_overlay(frame: &mut Frame, app: &App) {
    let area = centered_rect(70, 70, frame.area());
    frame.render_widget(Clear, area);

    let block = Block::default()
        .title(" Next Actions ")
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Green));

    let inner = block.inner(area);
    frame.render_widget(block, area);

    let chunks = Layout::vertical([
        Constraint::Min(5),    // List
        Constraint::Length(2), // Actions
    ])
    .split(inner);

    if let Some(ref actions) = app.next_actions_view.cache {
        let items: Vec<ListItem> = actions
            .iter()
            .enumerate()
            .map(|(i, action)| {
                let pri_color = match action.priority.as_str() {
                    "high" => Color::Red,
                    "medium" => Color::Yellow,
                    _ => Color::Green,
                };
                let selected = i == app.next_actions_view.nav.selected_index;
                let style = if selected {
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD)
                } else {
                    Style::default()
                };

                let mut spans = vec![
                    Span::styled(
                        format!(" {:>6} ", action.priority),
                        Style::default().fg(pri_color).add_modifier(Modifier::BOLD),
                    ),
                    Span::styled(&action.title, style),
                    Span::styled(
                        format!("  {}", action.reason),
                        Style::default().fg(Color::DarkGray),
                    ),
                ];

                if let Some(ref hint) = action.command_hint {
                    spans.push(Span::styled(
                        format!("  [{}]", hint),
                        Style::default().fg(Color::Cyan),
                    ));
                }

                ListItem::new(Line::from(spans))
            })
            .collect();

        if items.is_empty() {
            let empty = Paragraph::new(" No recommended actions")
                .style(Style::default().fg(Color::DarkGray));
            frame.render_widget(empty, chunks[0]);
        } else {
            let list = List::new(items);
            frame.render_widget(list, chunks[0]);
        }
    } else {
        let empty = Paragraph::new(" No action data").style(Style::default().fg(Color::DarkGray));
        frame.render_widget(empty, chunks[0]);
    }

    let footer = Paragraph::new(" j/k: scroll | Esc/q: close")
        .alignment(Alignment::Center)
        .style(Style::default().fg(Color::DarkGray));
    frame.render_widget(footer, chunks[1]);
}

/// Render the handoff view overlay
pub(crate) fn render_handoff_view_overlay(frame: &mut Frame, app: &App) {
    let area = centered_rect(75, 75, frame.area());
    frame.render_widget(Clear, area);

    let block = Block::default()
        .title(" AI Handoff ")
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::Magenta));

    let inner = block.inner(area);
    frame.render_widget(block, area);

    let chunks = Layout::vertical([
        Constraint::Length(2), // Target header
        Constraint::Min(5),    // Content
        Constraint::Length(2), // Actions
    ])
    .split(inner);

    if let Some(ref ctx) = app.handoff_view.cache {
        // Target header
        let target_color = match ctx.target.as_str() {
            "claude" => Color::Magenta,
            "codex" => Color::Green,
            "copilot" => Color::Blue,
            _ => Color::White,
        };
        let header = Paragraph::new(Line::from(vec![
            Span::styled(" Target: ", Style::default().fg(Color::DarkGray)),
            Span::styled(
                ctx.target.to_uppercase(),
                Style::default()
                    .fg(target_color)
                    .add_modifier(Modifier::BOLD),
            ),
            Span::styled("  Generated: ", Style::default().fg(Color::DarkGray)),
            Span::raw(&ctx.generated_at),
        ]));
        frame.render_widget(header, chunks[0]);

        // Content: prompt + next actions
        let mut lines: Vec<Line> = Vec::new();

        // Prompt section
        lines.push(Line::from(Span::styled(
            "── Prompt ──",
            Style::default()
                .fg(Color::Yellow)
                .add_modifier(Modifier::BOLD),
        )));
        // Show prompt text (truncate long prompts per line)
        for prompt_line in ctx.prompt.lines() {
            lines.push(Line::from(Span::styled(
                format!("  {}", prompt_line),
                Style::default().fg(Color::White),
            )));
        }

        // Next actions section
        if !ctx.next_actions.is_empty() {
            lines.push(Line::from(""));
            lines.push(Line::from(Span::styled(
                "── Next Actions ──",
                Style::default()
                    .fg(Color::Green)
                    .add_modifier(Modifier::BOLD),
            )));
            for (i, action) in ctx.next_actions.iter().enumerate() {
                let pri_color = match action.priority.as_str() {
                    "high" => Color::Red,
                    "medium" => Color::Yellow,
                    _ => Color::Green,
                };
                let selected = i + 1 == app.handoff_view.nav.selected_index;
                let style = if selected {
                    Style::default()
                        .fg(Color::White)
                        .add_modifier(Modifier::BOLD)
                } else {
                    Style::default()
                };
                lines.push(Line::from(vec![
                    Span::styled(
                        format!("  [{}] ", action.priority),
                        Style::default().fg(pri_color),
                    ),
                    Span::styled(&action.title, style),
                    Span::styled(
                        format!("  {}", action.reason),
                        Style::default().fg(Color::DarkGray),
                    ),
                ]));
            }
        }

        let content = Paragraph::new(lines)
            .wrap(ratatui::widgets::Wrap { trim: false })
            .scroll((app.handoff_view.nav.scroll_offset as u16, 0));
        frame.render_widget(content, chunks[1]);
    } else {
        let empty = Paragraph::new(" No handoff data").style(Style::default().fg(Color::DarkGray));
        frame.render_widget(empty, chunks[1]);
    }

    let footer = Paragraph::new(" j/k: scroll | y: copy to clipboard | Esc/q: close")
        .alignment(Alignment::Center)
        .style(Style::default().fg(Color::DarkGray));
    frame.render_widget(footer, chunks[2]);
}

/// Create a centered rectangle
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
    let popup_layout = Layout::vertical([
        Constraint::Percentage((100 - percent_y) / 2),
        Constraint::Percentage(percent_y),
        Constraint::Percentage((100 - percent_y) / 2),
    ])
    .split(r);

    Layout::horizontal([
        Constraint::Percentage((100 - percent_x) / 2),
        Constraint::Percentage(percent_x),
        Constraint::Percentage((100 - percent_x) / 2),
    ])
    .split(popup_layout[1])[1]
}