graphrag_cli/action.rs
1//! Action types for event-driven architecture
2//!
3//! Actions represent all possible events and state changes in the application.
4//! They are used to communicate between components and drive the application's
5//! event loop.
6
7use std::path::PathBuf;
8
9/// Query execution mode
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
11pub enum QueryMode {
12 /// Plain ask() - fastest, no metadata
13 #[default]
14 Ask,
15 /// ask_explained() - returns confidence + sources
16 Explain,
17 /// ask_with_reasoning() - query decomposition for complex questions
18 Reason,
19}
20
21impl QueryMode {
22 /// Short label for status bar display
23 pub fn label(&self) -> &'static str {
24 match self {
25 QueryMode::Ask => "ASK",
26 QueryMode::Explain => "EXPLAIN",
27 QueryMode::Reason => "REASON",
28 }
29 }
30}
31
32/// Source reference payload from an explained query
33#[derive(Debug, Clone, PartialEq)]
34pub struct SourceRef {
35 pub id: String,
36 pub excerpt: String,
37 pub relevance_score: f32,
38}
39
40/// Payload from a successful explained query (carried by `Action::QueryExplainedSuccess`)
41#[derive(Debug, Clone, PartialEq)]
42pub struct QueryExplainedPayload {
43 pub answer: String,
44 pub confidence: f32,
45 pub sources: Vec<SourceRef>,
46}
47
48/// Main action enum for application events
49#[derive(Debug, Clone, PartialEq)]
50#[allow(dead_code)]
51pub enum Action {
52 // ========= Application Lifecycle =========
53 /// Periodic tick for animations/updates
54 Tick,
55 /// Trigger a render
56 Render,
57 /// Terminal was resized
58 Resize(u16, u16),
59 /// Quit the application
60 Quit,
61
62 // ========= Input Handling =========
63 /// Insert a character at cursor
64 InputChar(char),
65 /// Delete character before cursor
66 DeleteChar,
67 /// Submit input (Enter key)
68 SubmitInput,
69 /// Clear all input
70 ClearInput,
71
72 // ========= Focus & Navigation =========
73 /// Focus the query input widget
74 FocusQueryInput,
75 /// Focus the results viewer widget
76 FocusResultsViewer,
77 /// Focus the raw results viewer widget
78 FocusRawResultsViewer,
79 /// Focus the info panel widget
80 FocusInfoPanel,
81 /// Move focus to next pane
82 NextPane,
83 /// Move focus to previous pane
84 PreviousPane,
85 /// Cycle to next tab in the focused panel (Tab key)
86 NextTab,
87
88 // ========= Scrolling (Vim-Style) =========
89 /// Scroll up one line (k)
90 ScrollUp,
91 /// Scroll down one line (j)
92 ScrollDown,
93 /// Scroll up one page (Ctrl+U)
94 ScrollPageUp,
95 /// Scroll down one page (Ctrl+D)
96 ScrollPageDown,
97 /// Scroll to top (Home)
98 ScrollToTop,
99 /// Scroll to bottom (End)
100 ScrollToBottom,
101
102 // ========= GraphRAG Operations =========
103 /// Load a configuration file (JSON5, JSON, TOML)
104 LoadConfig(PathBuf),
105 /// Load a document into the knowledge graph
106 LoadDocument(PathBuf),
107 /// Execute a natural language query using the current QueryMode
108 ExecuteQuery(String),
109 /// Execute a query explicitly in Explain mode (confidence + sources)
110 ExecuteExplainedQuery(String),
111 /// Execute a query explicitly in Reason mode (query decomposition)
112 ExecuteReasonQuery(String),
113 /// Execute a slash command
114 ExecuteSlashCommand(String),
115
116 // ========= Query Mode =========
117 /// Switch the default query mode
118 SetQueryMode(QueryMode),
119
120 // ========= Status Updates =========
121 /// Set status message with type
122 SetStatus(StatusType, String),
123 /// Clear current status
124 ClearStatus,
125 /// Show progress indicator
126 StartProgress(String),
127 /// Stop progress indicator
128 StopProgress,
129
130 // ========= Help System =========
131 /// Toggle help overlay
132 ToggleHelp,
133
134 // ========= Async Operation Results =========
135 /// Query completed successfully (plain answer)
136 QuerySuccess(String),
137 /// Explained query completed (answer + confidence + sources)
138 QueryExplainedSuccess(Box<QueryExplainedPayload>),
139 /// Query failed with error
140 QueryError(String),
141 /// Document loaded successfully
142 DocumentLoaded(String),
143 /// Document load failed
144 DocumentLoadError(String),
145 /// Configuration loaded successfully
146 ConfigLoaded(String),
147 /// Configuration load failed
148 ConfigLoadError(String),
149 /// Export history completed
150 ExportSuccess(String),
151
152 // ========= Workspace Operations =========
153 /// Switch to a different workspace
154 SwitchWorkspace(String),
155 /// Refresh workspace statistics
156 RefreshStats,
157
158 // ========= No Operation =========
159 /// No action to perform
160 Noop,
161}
162
163/// Status indicator types with associated colors
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
165pub enum StatusType {
166 /// Information (blue ℹ)
167 Info,
168 /// Success (green ✓)
169 Success,
170 /// Warning (yellow ⚠)
171 Warning,
172 /// Error (red ✗)
173 Error,
174 /// Progress (cyan ⟳)
175 Progress,
176}
177
178impl StatusType {
179 /// Get the icon symbol for this status type
180 pub fn icon(&self) -> &str {
181 match self {
182 StatusType::Info => "ℹ",
183 StatusType::Success => "✓",
184 StatusType::Warning => "⚠",
185 StatusType::Error => "✗",
186 StatusType::Progress => "⟳",
187 }
188 }
189
190 /// Get the color for this status type
191 pub fn color(&self) -> ratatui::style::Color {
192 use ratatui::style::Color;
193 match self {
194 StatusType::Info => Color::Blue,
195 StatusType::Success => Color::Green,
196 StatusType::Warning => Color::Yellow,
197 StatusType::Error => Color::Red,
198 StatusType::Progress => Color::Cyan,
199 }
200 }
201}