git-iris 2.1.0

AI-powered Git workflow assistant for smart commits, code reviews, changelogs, and release notes
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
//! Mode-specific state structs for Iris Studio
//!
//! Each mode (Explore, Commit, Review, PR, Changelog, `ReleaseNotes`) has its own state struct.

use std::path::PathBuf;

use crate::types::GeneratedMessage;

use super::super::components::{CodeViewState, DiffViewState, FileTreeState, MessageEditorState};
use super::EmojiMode;

// ═══════════════════════════════════════════════════════════════════════════════
// Explore Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// A commit entry in the file log
#[derive(Debug, Clone)]
pub struct FileLogEntry {
    /// Full commit hash
    pub hash: String,
    /// Short hash (7 chars)
    pub short_hash: String,
    /// Commit message (first line)
    pub message: String,
    /// Author name
    pub author: String,
    /// Relative time (e.g., "2 days ago")
    pub relative_time: String,
    /// Lines added in this commit for the file
    pub additions: Option<usize>,
    /// Lines removed in this commit for the file
    pub deletions: Option<usize>,
}

/// State for Explore mode
#[derive(Default)]
#[allow(clippy::struct_excessive_bools)]
pub struct ExploreState {
    /// Currently selected file
    pub current_file: Option<PathBuf>,
    /// Current line in code view
    pub current_line: usize,
    /// Selection range (start, end) for multi-line queries
    pub selection: Option<(usize, usize)>,
    /// Selection anchor line for visual mode (where 'v' was pressed)
    pub selection_anchor: Option<usize>,
    /// Code view scroll offset
    pub code_scroll: usize,
    /// Heat map enabled
    pub show_heat_map: bool,
    /// File tree state
    pub file_tree: FileTreeState,
    /// Code view state
    pub code_view: CodeViewState,
    /// Current semantic blame result (for context panel)
    pub semantic_blame: Option<super::super::events::SemanticBlameResult>,
    /// Streaming blame content (while generating)
    pub streaming_blame: Option<String>,
    /// Whether semantic blame is loading
    pub blame_loading: bool,
    /// File log entries for the currently selected file
    pub file_log: Vec<FileLogEntry>,
    /// Selected index in file log
    pub file_log_selected: usize,
    /// Scroll offset for file log
    pub file_log_scroll: usize,
    /// Whether file log is loading
    pub file_log_loading: bool,
    /// Global commit log (all commits, not file-specific)
    pub global_log: Vec<FileLogEntry>,
    /// Whether to show global log instead of file log
    pub show_global_log: bool,
    /// Whether global log is loading
    pub global_log_loading: bool,
    /// Pending file log path (for deferred loading after event loop starts)
    pub pending_file_log: Option<PathBuf>,
}

impl std::fmt::Debug for ExploreState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ExploreState")
            .field("current_file", &self.current_file)
            .field("current_line", &self.current_line)
            .field("selection", &self.selection)
            .field("code_scroll", &self.code_scroll)
            .field("show_heat_map", &self.show_heat_map)
            .finish_non_exhaustive()
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Commit Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// State for Commit mode
#[allow(clippy::struct_excessive_bools)]
pub struct CommitState {
    /// Generated commit messages
    pub messages: Vec<GeneratedMessage>,
    /// Index of current message
    pub current_index: usize,
    /// Custom instructions for regeneration
    pub custom_instructions: String,
    /// Selected file in staged list
    pub selected_file_index: usize,
    /// Is message being edited
    pub editing_message: bool,
    /// Is generating new message
    pub generating: bool,
    /// Use gitmoji (legacy toggle, replaced by `emoji_mode`)
    pub use_gitmoji: bool,
    /// Current emoji mode (None, Auto, or Custom)
    pub emoji_mode: EmojiMode,
    /// Current preset name
    pub preset: String,
    /// File tree state for staged files
    pub file_tree: FileTreeState,
    /// Diff view state
    pub diff_view: DiffViewState,
    /// Message editor state
    pub message_editor: MessageEditorState,
    /// Show all tracked files (vs only staged/modified)
    pub show_all_files: bool,
    /// Whether we're amending the previous commit
    pub amend_mode: bool,
    /// Original commit message (when amending)
    pub original_message: Option<String>,
}

impl Default for CommitState {
    fn default() -> Self {
        Self {
            messages: Vec::new(),
            current_index: 0,
            custom_instructions: String::new(),
            selected_file_index: 0,
            editing_message: false,
            generating: false,
            use_gitmoji: true,
            emoji_mode: EmojiMode::Auto,
            preset: "default".to_string(),
            file_tree: FileTreeState::new(),
            diff_view: DiffViewState::new(),
            message_editor: MessageEditorState::new(),
            show_all_files: false,
            amend_mode: false,
            original_message: None,
        }
    }
}

impl std::fmt::Debug for CommitState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("CommitState")
            .field("messages_count", &self.messages.len())
            .field("current_index", &self.current_index)
            .field("selected_file_index", &self.selected_file_index)
            .field("editing_message", &self.editing_message)
            .field("generating", &self.generating)
            .field("amend_mode", &self.amend_mode)
            .finish_non_exhaustive()
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Review Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// State for Review mode
pub struct ReviewState {
    /// File tree for changed files
    pub file_tree: FileTreeState,
    /// Diff view for selected file
    pub diff_view: DiffViewState,
    /// Generated structured review
    pub review: Option<crate::types::Review>,
    /// Generated review content (markdown)
    pub review_content: String,
    /// Review scroll offset
    pub review_scroll: usize,
    /// Whether a review is being generated
    pub generating: bool,
    /// From ref for comparison (defaults to HEAD~1 for most recent commit)
    pub from_ref: String,
    /// To ref for comparison (defaults to HEAD)
    pub to_ref: String,
}

impl Default for ReviewState {
    fn default() -> Self {
        Self {
            file_tree: FileTreeState::default(),
            diff_view: DiffViewState::default(),
            review: None,
            review_content: String::new(),
            review_scroll: 0,
            generating: false,
            from_ref: "HEAD~1".to_string(),
            to_ref: "HEAD".to_string(),
        }
    }
}

impl ReviewState {
    pub fn reset_review(&mut self) {
        self.review = None;
        self.review_content.clear();
        self.review_scroll = 0;
    }
}

impl std::fmt::Debug for ReviewState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ReviewState")
            .field("review_content_len", &self.review_content.len())
            .field(
                "findings_count",
                &self.review.as_ref().map(|review| review.findings.len()),
            )
            .field("review_scroll", &self.review_scroll)
            .field("generating", &self.generating)
            .finish_non_exhaustive()
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// PR Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// A commit entry for PR mode
#[derive(Debug, Clone)]
pub struct PrCommit {
    /// Short commit hash
    pub hash: String,
    /// Commit message (first line)
    pub message: String,
    /// Author name
    pub author: String,
}

/// State for PR mode
pub struct PrState {
    /// Base branch for PR comparison (from ref)
    pub base_branch: String,
    /// Target ref (defaults to HEAD)
    pub to_ref: String,
    /// Commits in this PR (from base to HEAD)
    pub commits: Vec<PrCommit>,
    /// Selected commit index
    pub selected_commit: usize,
    /// Commit list scroll offset
    pub commit_scroll: usize,
    /// File tree for changed files
    pub file_tree: FileTreeState,
    /// Diff view state
    pub diff_view: DiffViewState,
    /// Generated PR description (markdown)
    pub pr_content: String,
    /// PR content scroll offset
    pub pr_scroll: usize,
    /// Whether PR description is being generated
    pub generating: bool,
}

impl Default for PrState {
    fn default() -> Self {
        Self {
            base_branch: "main".to_string(),
            to_ref: "HEAD".to_string(),
            commits: Vec::new(),
            selected_commit: 0,
            commit_scroll: 0,
            file_tree: FileTreeState::new(),
            diff_view: DiffViewState::new(),
            pr_content: String::new(),
            pr_scroll: 0,
            generating: false,
        }
    }
}

impl std::fmt::Debug for PrState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("PrState")
            .field("base_branch", &self.base_branch)
            .field("commits_count", &self.commits.len())
            .field("selected_commit", &self.selected_commit)
            .field("pr_content_len", &self.pr_content.len())
            .field("generating", &self.generating)
            .finish_non_exhaustive()
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Changelog Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// A commit for display in changelog mode
#[derive(Debug, Clone)]
pub struct ChangelogCommit {
    /// Short commit hash
    pub hash: String,
    /// Commit message (first line)
    pub message: String,
    /// Author name
    pub author: String,
}

/// State for Changelog mode
#[derive(Debug)]
pub struct ChangelogState {
    /// Version range start (from ref)
    pub from_ref: String,
    /// Version range end (to ref)
    pub to_ref: String,
    /// Commits between refs
    pub commits: Vec<ChangelogCommit>,
    /// Selected commit index
    pub selected_commit: usize,
    /// Commit list scroll offset
    pub commit_scroll: usize,
    /// Diff view state
    pub diff_view: DiffViewState,
    /// Generated changelog content (markdown)
    pub changelog_content: String,
    /// Changelog content scroll offset
    pub changelog_scroll: usize,
    /// Whether changelog is being generated
    pub generating: bool,
}

impl Default for ChangelogState {
    fn default() -> Self {
        Self {
            from_ref: "HEAD~1".to_string(),
            to_ref: "HEAD".to_string(),
            commits: Vec::new(),
            selected_commit: 0,
            commit_scroll: 0,
            diff_view: DiffViewState::new(),
            changelog_content: String::new(),
            changelog_scroll: 0,
            generating: false,
        }
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Release Notes Mode
// ═══════════════════════════════════════════════════════════════════════════════

/// State for Release Notes mode
#[derive(Debug)]
pub struct ReleaseNotesState {
    /// Version range start (from ref)
    pub from_ref: String,
    /// Version range end (to ref)
    pub to_ref: String,
    /// Commits between refs
    pub commits: Vec<ChangelogCommit>,
    /// Selected commit index
    pub selected_commit: usize,
    /// Commit list scroll offset
    pub commit_scroll: usize,
    /// Diff view state
    pub diff_view: DiffViewState,
    /// Generated release notes content (markdown)
    pub release_notes_content: String,
    /// Release notes content scroll offset
    pub release_notes_scroll: usize,
    /// Whether release notes are being generated
    pub generating: bool,
}

impl Default for ReleaseNotesState {
    fn default() -> Self {
        Self {
            from_ref: "HEAD~1".to_string(),
            to_ref: "HEAD".to_string(),
            commits: Vec::new(),
            selected_commit: 0,
            commit_scroll: 0,
            diff_view: DiffViewState::new(),
            release_notes_content: String::new(),
            release_notes_scroll: 0,
            generating: false,
        }
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// Mode States Container
// ═══════════════════════════════════════════════════════════════════════════════

/// Container for all mode states
#[derive(Debug, Default)]
pub struct ModeStates {
    pub explore: ExploreState,
    pub commit: CommitState,
    pub review: ReviewState,
    pub pr: PrState,
    pub changelog: ChangelogState,
    pub release_notes: ReleaseNotesState,
}