mutiny-diff 0.1.22

TUI git diff viewer with worktree management
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
# Spec: Agent Feedback Summary View

**Priority**: P1
**Status**: Ready for implementation
**Estimated effort**: Medium-Large (5-8 files changed)

## Problem

After reviewing an agent's changeset and leaving annotations and scores, the reviewer has no way to see the aggregate picture. Annotations are scattered across files, and there's no summary answering: "How many issues did I find? What categories? What's the overall quality?" This makes it hard to:

1. Assess overall agent performance before sending feedback
2. Compare agent quality across iterations
3. Communicate a high-level verdict to the agent alongside detailed annotations
4. Decide whether to accept, reject, or request revisions

The feedback loop is incomplete without a summary view that aggregates all structured feedback into an actionable overview.

## Design

### Toggle & Layout

- **Key**: `F` (in DiffExplorer view, not in visual mode)
- **Layout**: Full-screen overlay panel (similar to prompt preview), replacing the diff view
- **Exit**: `Esc` or `F` again to toggle back

### Summary Sections

#### Header
```
┌─────────────────────────────────────────────────┐
│  Feedback Summary — my-feature-branch            │
│  12 annotations · 34 scores · 8/20 files reviewed│
└─────────────────────────────────────────────────┘
```

#### Annotation Breakdown (by Category)
```
  Category        Count
  ─────────────────────
  Bug             ███░░░░░░░  3
  Style           █░░░░░░░░░  1
  Performance     ██░░░░░░░░  2
  Security        ░░░░░░░░░░  0
  Suggestion      ████░░░░░░  4
  Question        █░░░░░░░░░  1
  Nitpick         █░░░░░░░░░  1
```

#### Severity Distribution
```
  Critical  ██        2
  Major     ███       3
  Minor     █████     5
  Info      ██        2
```

#### Score Distribution (if quick-reactions are implemented)
```
  Score Distribution (34 lines scored)
  1 ●  ████████    8  (24%)
  2 ●  ██████      6  (18%)
  3 ●  ████████    8  (24%)
  4 ●  ██████████  10 (29%)
  5 ●  ██          2  (6%)
  
  Average: 2.8/5
```

#### Per-File Annotation Density
```
  File                          Annotations  Scores  Avg Score
  ─────────────────────────────────────────────────────────────
  src/main.rs                   4            12      2.3
  src/state/app_state.rs        3            8       3.1
  src/components/diff_view.rs   2            6       2.8
  src/event.rs                  2            5       3.5
  tests/integration.rs          1            3       4.2
```

#### Export Actions
```
  [y] Copy JSON to clipboard  [p] Copy as prompt text  [Esc] Close
```

### JSON Export Format

```json
{
  "session": "my-feature-branch",
  "timestamp": "2026-03-05T10:00:00Z",
  "summary": {
    "total_annotations": 12,
    "total_scores": 34,
    "files_reviewed": 8,
    "files_total": 20,
    "average_score": 2.8
  },
  "categories": {
    "Bug": 3,
    "Style": 1,
    "Performance": 2,
    "Security": 0,
    "Suggestion": 4,
    "Question": 1,
    "Nitpick": 1
  },
  "severities": {
    "Critical": 2,
    "Major": 3,
    "Minor": 5,
    "Info": 2
  },
  "score_distribution": {
    "1": 8,
    "2": 6,
    "3": 8,
    "4": 10,
    "5": 2
  },
  "files": [
    {
      "path": "src/main.rs",
      "annotations": 4,
      "scores": 12,
      "average_score": 2.3
    }
  ]
}
```

## Implementation

### 1. `src/state/app_state.rs` — Add feedback summary state

```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActiveView {
    DiffExplorer,
    WorktreeBrowser,
    AgentOutputs,
    FeedbackSummary, // NEW
}
```

Add to `AppState`:

```rust
// Feedback summary
pub feedback_summary_scroll: usize,
```

Initialize `feedback_summary_scroll` to `0` in `AppState::new()`.

### 2. `src/action.rs` — Add actions

```rust
// Feedback summary
ToggleFeedbackSummary,
FeedbackSummaryUp,
FeedbackSummaryDown,
FeedbackSummaryCopyJson,
FeedbackSummaryCopyPrompt,
```

### 3. `src/event.rs` — Add keybindings

In Priority 6 (Diff explorer global bindings), add:

```rust
KeyCode::Char('F') => return Some(Action::ToggleFeedbackSummary),
```

Add a new priority block for the FeedbackSummary view (after AgentOutputs, Priority 5.5):

```rust
// Priority 5.6: Feedback summary view
if ctx.active_view == ActiveView::FeedbackSummary {
    return match key.code {
        KeyCode::Up | KeyCode::Char('k') => Some(Action::FeedbackSummaryUp),
        KeyCode::Down | KeyCode::Char('j') => Some(Action::FeedbackSummaryDown),
        KeyCode::Char('y') => Some(Action::FeedbackSummaryCopyJson),
        KeyCode::Char('p') => Some(Action::FeedbackSummaryCopyPrompt),
        KeyCode::Esc | KeyCode::Char('F') => Some(Action::ToggleFeedbackSummary),
        _ => None,
    };
}
```

Add `active_view` check in `KeyContext` (it's already there).

### 4. `src/app.rs` — Handle actions

```rust
Action::ToggleFeedbackSummary => {
    if self.state.active_view == ActiveView::FeedbackSummary {
        self.state.active_view = ActiveView::DiffExplorer;
    } else {
        self.state.active_view = ActiveView::FeedbackSummary;
        self.state.feedback_summary_scroll = 0;
    }
}

Action::FeedbackSummaryUp => {
    self.state.feedback_summary_scroll = self.state.feedback_summary_scroll.saturating_sub(1);
}

Action::FeedbackSummaryDown => {
    self.state.feedback_summary_scroll += 1;
}

Action::FeedbackSummaryCopyJson => {
    let json = self.build_feedback_summary_json();
    if let Ok(text) = serde_json::to_string_pretty(&json) {
        if let Ok(mut clipboard) = arboard::Clipboard::new() {
            let _ = clipboard.set_text(&text);
            self.state.status_message = Some(("Feedback JSON copied to clipboard".to_string(), false));
        }
    }
}

Action::FeedbackSummaryCopyPrompt => {
    let prompt_text = self.build_feedback_summary_prompt();
    if let Ok(mut clipboard) = arboard::Clipboard::new() {
        let _ = clipboard.set_text(&prompt_text);
        self.state.status_message = Some(("Feedback summary copied to clipboard".to_string(), false));
    }
}
```

Add helper methods to the `App` impl:

```rust
fn build_feedback_summary_json(&self) -> serde_json::Value {
    let annotations = &self.state.annotations;
    
    // Count by category (requires annotation categories from spec 002)
    // If categories are not yet implemented, use a simpler count
    let total_annotations = annotations.count();
    let total_scores = annotations.score_count();
    let files_with_annotations: std::collections::HashSet<&str> = 
        annotations.annotations.keys().map(|s| s.as_str()).collect();
    let total_files = self.state.navigator.file_count(); // or however files are counted
    
    // Score distribution
    let all_scores = annotations.all_scores_sorted();
    let mut score_dist = [0usize; 5];
    let mut score_sum = 0usize;
    for s in &all_scores {
        if s.score >= 1 && s.score <= 5 {
            score_dist[(s.score - 1) as usize] += 1;
            score_sum += s.score as usize;
        }
    }
    let avg_score = if total_scores > 0 {
        score_sum as f64 / total_scores as f64
    } else {
        0.0
    };
    
    serde_json::json!({
        "timestamp": chrono::Utc::now().to_rfc3339(),
        "summary": {
            "total_annotations": total_annotations,
            "total_scores": total_scores,
            "files_with_feedback": files_with_annotations.len(),
            "files_total": total_files,
            "average_score": (avg_score * 10.0).round() / 10.0,
        },
        "score_distribution": {
            "1": score_dist[0],
            "2": score_dist[1],
            "3": score_dist[2],
            "4": score_dist[3],
            "5": score_dist[4],
        }
    })
}

fn build_feedback_summary_prompt(&self) -> String {
    let json = self.build_feedback_summary_json();
    let total = json["summary"]["total_annotations"].as_u64().unwrap_or(0);
    let scores = json["summary"]["total_scores"].as_u64().unwrap_or(0);
    let avg = json["summary"]["average_score"].as_f64().unwrap_or(0.0);
    
    format!(
        "## Review Summary\n\n\
         - {} annotations across {} files\n\
         - {} lines scored, average quality: {:.1}/5\n\n\
         See detailed annotations in the full prompt output.",
        total,
        json["summary"]["files_with_feedback"],
        scores,
        avg,
    )
}
```

### 5. `src/components/feedback_summary.rs` — New component

Create a new component for rendering the feedback summary view:

```rust
use ratatui::{
    layout::{Constraint, Direction, Layout, Rect},
    style::{Color, Modifier, Style},
    text::{Line, Span},
    widgets::{Block, Borders, Paragraph, Wrap},
    Frame,
};

use crate::state::AppState;
use super::Component;

pub struct FeedbackSummary;

impl Component for FeedbackSummary {
    fn render(&self, frame: &mut Frame, area: Rect, state: &AppState) {
        let block = Block::default()
            .title(" Feedback Summary ")
            .borders(Borders::ALL)
            .border_style(Style::default().fg(state.theme.accent));

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

        let mut lines: Vec<Line> = Vec::new();

        // Header
        let total_ann = state.annotations.count();
        let total_scores = state.annotations.score_count();
        let reviewed = state.review.reviewed_count();
        let total_files = state.navigator.file_count();

        lines.push(Line::from(vec![
            Span::styled(
                format!("  {} annotations", total_ann),
                Style::default().fg(state.theme.accent).add_modifier(Modifier::BOLD),
            ),
            Span::raw(" · "),
            Span::styled(
                format!("{} scores", total_scores),
                Style::default().fg(state.theme.accent),
            ),
            Span::raw(" · "),
            Span::styled(
                format!("{}/{} files reviewed", reviewed, total_files),
                Style::default().fg(state.theme.text_muted),
            ),
        ]));
        lines.push(Line::from(""));

        // Score distribution
        if total_scores > 0 {
            lines.push(Line::from(Span::styled(
                "  Score Distribution",
                Style::default().add_modifier(Modifier::BOLD).fg(state.theme.text),
            )));
            lines.push(Line::from(""));

            let all_scores = state.annotations.all_scores_sorted();
            let mut dist = [0usize; 5];
            let mut sum = 0usize;
            for s in &all_scores {
                if s.score >= 1 && s.score <= 5 {
                    dist[(s.score - 1) as usize] += 1;
                    sum += s.score as usize;
                }
            }

            let max_count = *dist.iter().max().unwrap_or(&1).max(&1);
            let bar_width = 20usize;
            let colors = [Color::Red, Color::Rgb(255, 165, 0), Color::Yellow, Color::Rgb(144, 238, 144), Color::Green];

            for (i, count) in dist.iter().enumerate() {
                let filled = if max_count > 0 { count * bar_width / max_count } else { 0 };
                let bar = "█".repeat(filled) + &"░".repeat(bar_width - filled);
                let pct = if total_scores > 0 { *count * 100 / total_scores } else { 0 };
                lines.push(Line::from(vec![
                    Span::styled(format!("  {} ", i + 1), Style::default().fg(colors[i])),
                    Span::styled("● ", Style::default().fg(colors[i])),
                    Span::styled(bar, Style::default().fg(colors[i])),
                    Span::styled(
                        format!("  {} ({}%)", count, pct),
                        Style::default().fg(state.theme.text_muted),
                    ),
                ]));
            }

            let avg = if total_scores > 0 { sum as f64 / total_scores as f64 } else { 0.0 };
            lines.push(Line::from(""));
            lines.push(Line::from(Span::styled(
                format!("  Average: {:.1}/5", avg),
                Style::default().add_modifier(Modifier::BOLD).fg(state.theme.text),
            )));
        }

        lines.push(Line::from(""));
        lines.push(Line::from(""));

        // Footer with actions
        lines.push(Line::from(vec![
            Span::styled("  [y]", Style::default().fg(state.theme.accent).add_modifier(Modifier::BOLD)),
            Span::raw(" Copy JSON  "),
            Span::styled("[p]", Style::default().fg(state.theme.accent).add_modifier(Modifier::BOLD)),
            Span::raw(" Copy prompt text  "),
            Span::styled("[Esc]", Style::default().fg(state.theme.text_muted)),
            Span::raw(" Close"),
        ]));

        // Apply scroll offset
        let visible_lines: Vec<Line> = lines
            .into_iter()
            .skip(state.feedback_summary_scroll)
            .collect();

        let paragraph = Paragraph::new(visible_lines).wrap(Wrap { trim: false });
        frame.render_widget(paragraph, inner);
    }
}
```

### 6. `src/components/mod.rs` — Register component

Add: `pub mod feedback_summary;`

### 7. Main render function — Route to summary view

In the main render logic, when `state.active_view == ActiveView::FeedbackSummary`, render the feedback summary component instead of the diff explorer:

```rust
match state.active_view {
    ActiveView::DiffExplorer => { /* existing render */ }
    ActiveView::WorktreeBrowser => { /* existing render */ }
    ActiveView::AgentOutputs => { /* existing render */ }
    ActiveView::FeedbackSummary => {
        feedback_summary::FeedbackSummary.render(frame, main_area, &state);
    }
}
```

## Dependencies

- **Soft dependency on spec 002** (annotation categories): The category/severity breakdown section requires categories to be implemented. If not yet available, show a simpler "Total annotations: N" without category breakdown.
- **Soft dependency on spec 003** (quick-reactions): The score distribution section requires scores. If not yet available, omit the score section.

Both dependencies are handled gracefully — the summary view works with whatever data is available.

## Testing

- Open mdiff with some annotations (and scores if available)
- Press `F` — verify summary view appears with correct counts
- Verify scroll works with `j`/`k`
- Press `y` — verify JSON copied to clipboard with correct structure
- Press `p` — verify prompt text copied
- Press `Esc` — verify returns to diff explorer
- Press `F` again — verify toggles back to summary
- Test with zero annotations — verify empty state renders cleanly
- Test with annotations but no scores — verify score section is omitted