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
use agcodex_core::protocol::Event;
use agcodex_core::subagents::InvocationRequest;
use agcodex_core::subagents::SubagentExecution;
use agcodex_file_search::FileMatch;
use agcodex_persistence::types::SessionMetadata;
use ratatui::crossterm::event::KeyEvent;
use ratatui::text::Line;
use std::time::Duration;
use uuid::Uuid;
use crate::app::ChatWidgetArgs;
use crate::slash_command::SlashCommand;
// Note: These imports will be used when session browser event handling is implemented
#[allow(unused_imports)]
use crate::widgets::FocusedPanel;
#[allow(unused_imports)]
use crate::widgets::SessionAction;
#[allow(unused_imports)]
use crate::widgets::SortBy;
#[allow(unused_imports)]
use crate::widgets::ViewMode;
use agcodex_core::protocol::AskForApproval;
use agcodex_core::protocol::SandboxPolicy;
use agcodex_core::protocol_config_types::ReasoningEffort;
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub(crate) enum AppEvent {
CodexEvent(Event),
/// Request a redraw which will be debounced by the [`App`].
RequestRedraw,
/// Actually draw the next frame.
Redraw,
/// Schedule a one-shot animation frame roughly after the given duration.
/// Multiple requests are coalesced by the central frame scheduler.
ScheduleFrameIn(Duration),
KeyEvent(KeyEvent),
/// Text pasted from the terminal clipboard.
Paste(String),
/// Request to exit the application gracefully.
ExitRequest,
/// Forward an `Op` to the Agent. Using an `AppEvent` for this avoids
/// bubbling channels through layers of widgets.
CodexOp(agcodex_core::protocol::Op),
/// Dispatch a recognized slash command from the UI (composer) to the app
/// layer so it can be handled centrally.
DispatchCommand(SlashCommand),
/// Kick off an asynchronous file search for the given query (text after
/// the `@`). Previous searches may be cancelled by the app layer so there
/// is at most one in-flight search.
StartFileSearch(String),
/// Result of a completed asynchronous file search. The `query` echoes the
/// original search term so the UI can decide whether the results are
/// still relevant.
FileSearchResult {
query: String,
matches: Vec<FileMatch>,
},
/// Result of computing a `/diff` command.
DiffResult(String),
InsertHistory(Vec<Line<'static>>),
StartCommitAnimation,
StopCommitAnimation,
CommitTick,
/// Onboarding: result of login_with_chatgpt.
OnboardingAuthComplete(Result<(), String>),
OnboardingComplete(ChatWidgetArgs),
/// Update the current reasoning effort in the running app and widget.
UpdateReasoningEffort(ReasoningEffort),
/// Update the current model slug in the running app and widget.
UpdateModel(String),
/// Update the current approval policy in the running app and widget.
UpdateAskForApprovalPolicy(AskForApproval),
/// Update the current sandbox policy in the running app and widget.
UpdateSandboxPolicy(SandboxPolicy),
/// Cycle to the next operating mode (Plan → Build → Review → Plan).
CycleModes,
/// Request to show the message jump popup.
ShowMessageJump,
/// Request to hide the message jump popup.
HideMessageJump,
/// Jump to a specific message index in the conversation history.
JumpToMessage(usize),
/// Update search query in message jump popup.
MessageJumpSearch(String),
/// Cycle role filter in message jump popup.
MessageJumpCycleFilter,
/// Open the save session dialog.
OpenSaveDialog,
/// Save session with the provided name and description.
SaveSession {
name: String,
description: Option<String>,
},
/// Close the save dialog.
CloseSaveDialog,
/// Open the load session dialog
OpenLoadDialog,
/// Close the load session dialog
CloseLoadDialog,
/// Start loading session list for the load dialog
StartLoadSessionList,
/// Result of loading session list
LoadSessionListResult(Result<Vec<SessionMetadata>, String>),
/// Load a specific session by ID
LoadSession(Uuid),
/// Result of loading a session
LoadSessionResult(Result<Uuid, String>),
/// Update search query in load dialog
UpdateLoadDialogQuery(String),
/// Open the session browser (Ctrl+H)
OpenSessionBrowser,
/// Close the session browser
CloseSessionBrowser,
/// Session browser: navigate up/down
SessionBrowserNavigate(i32),
/// Session browser: change panel focus
SessionBrowserFocusNext,
SessionBrowserFocusPrevious,
/// Session browser: toggle view mode
SessionBrowserToggleViewMode,
/// Session browser: cycle sort order
SessionBrowserCycleSort,
/// Session browser: update search query
SessionBrowserUpdateSearch(String),
/// Session browser: execute selected action
SessionBrowserExecuteAction,
/// Session browser: delete session
SessionBrowserDeleteSession(Uuid),
/// Session browser: export session
SessionBrowserExportSession {
id: Uuid,
format: String,
},
/// Session browser: rename session
SessionBrowserRenameSession {
id: Uuid,
new_name: String,
},
/// Session browser: toggle favorite
SessionBrowserToggleFavorite(Uuid),
/// Session browser: duplicate session
SessionBrowserDuplicateSession(Uuid),
/// Session browser: show confirmation dialog
SessionBrowserShowConfirmation(String),
/// Session browser: confirm action
SessionBrowserConfirmAction(bool),
/// Session browser: toggle favorites filter
SessionBrowserToggleFavoritesFilter,
/// Session browser: toggle expand
SessionBrowserToggleExpand,
/// Session browser: select item
SessionBrowserSelect,
/// Session browser: delete item
SessionBrowserDelete,
/// Session browser: filter
SessionBrowserFilter(String),
/// Session browser: sort
SessionBrowserSort(String),
/// Start history get operation
StartHistoryGet,
/// History get result
HistoryGetResult(String),
/// Start jump to message operation
StartJumpToMessage(usize),
/// Start undo operation
StartUndo,
/// Undo complete
UndoComplete,
/// Start redo operation
StartRedo,
/// Redo complete
RedoComplete,
/// Start fork operation
StartFork,
/// Fork complete
ForkComplete(String),
// ===== Agent Events =====
/// Start agent execution from invocation request
StartAgent(InvocationRequest),
/// Agent execution progress update
AgentProgress {
agent_id: Uuid,
progress: f32, // 0.0 to 1.0
message: String, // Current status message
},
/// Agent execution completed
AgentComplete {
agent_id: Uuid,
execution: SubagentExecution,
},
/// Agent execution failed
AgentFailed {
agent_id: Uuid,
error: String,
},
/// Cancel running agent
CancelAgent(Uuid),
/// Toggle agent panel visibility (Ctrl+A)
ToggleAgentPanel,
/// Agent panel navigation events
AgentPanelNavigateUp,
AgentPanelNavigateDown,
AgentPanelCancel,
/// Agent output chunk received (for streaming)
AgentOutputChunk {
agent_id: Uuid,
chunk: String,
},
}