Skip to main content

git_iris/
context.rs

1use serde::Serialize;
2use std::fmt;
3
4/// Git context information for pre-flight checks and TUI display.
5/// The agent gathers detailed context dynamically via tools.
6#[derive(Serialize, Debug, Clone)]
7pub struct CommitContext {
8    pub branch: String,
9    pub recent_commits: Vec<RecentCommit>,
10    pub staged_files: Vec<StagedFile>,
11    pub user_name: String,
12    pub user_email: String,
13}
14
15#[derive(Serialize, Debug, Clone)]
16pub struct RecentCommit {
17    pub hash: String,
18    pub message: String,
19    pub author: String,
20    pub timestamp: String,
21}
22
23#[derive(Serialize, Debug, Clone)]
24pub struct StagedFile {
25    pub path: String,
26    pub change_type: ChangeType,
27    pub diff: String,
28    pub content: Option<String>,
29    pub content_excluded: bool,
30}
31
32#[derive(Serialize, Debug, Clone, PartialEq, Eq)]
33pub enum ChangeType {
34    Added,
35    Modified,
36    Deleted,
37}
38
39impl fmt::Display for ChangeType {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Self::Added => write!(f, "Added"),
43            Self::Modified => write!(f, "Modified"),
44            Self::Deleted => write!(f, "Deleted"),
45        }
46    }
47}
48
49impl CommitContext {
50    #[must_use]
51    pub fn new(
52        branch: String,
53        recent_commits: Vec<RecentCommit>,
54        staged_files: Vec<StagedFile>,
55        user_name: String,
56        user_email: String,
57    ) -> Self {
58        Self {
59            branch,
60            recent_commits,
61            staged_files,
62            user_name,
63            user_email,
64        }
65    }
66}