yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_chat_widget.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_AGENT_AGENT_CHAT_WIDGET_H_
2#define YAZE_APP_EDITOR_AGENT_AGENT_CHAT_WIDGET_H_
3
4#include <filesystem>
5#include <functional>
6#include <optional>
7#include <string>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12#include "absl/time/time.h"
18#include "app/core/project.h"
19
20namespace yaze {
21
22class Rom;
23
24namespace editor {
25
26class ProposalDrawer;
27class ToastManager;
28class AgentChatHistoryPopup;
29
45 public:
47
48 void Draw();
49
50 void SetRomContext(Rom* rom);
51
54 std::string session_id;
55 std::string session_name;
56 std::vector<std::string> participants;
57 };
58
59 std::function<absl::StatusOr<SessionContext>(const std::string&)> host_session;
60 std::function<absl::StatusOr<SessionContext>(const std::string&)> join_session;
61 std::function<absl::Status()> leave_session;
62 std::function<absl::StatusOr<SessionContext>()> refresh_session;
63 };
64
66 std::function<absl::Status(std::filesystem::path*)> capture_snapshot;
67 std::function<absl::Status(const std::filesystem::path&, const std::string&)> send_to_gemini;
68 };
69
71 std::function<void()> open_harness_dashboard;
72 std::function<void()> replay_last_plan;
73 std::function<void(const std::string&)> focus_proposal;
74 std::function<void()> show_active_tests;
75 };
76
78 std::string test_id;
79 std::string name;
80 std::string status;
81 std::string message;
82 absl::Time updated_at = absl::InfinitePast();
83 };
84
85 // Z3ED Command Callbacks
87 std::function<absl::Status(const std::string&)> run_agent_task;
88 std::function<absl::StatusOr<std::string>(const std::string&)> plan_agent_task;
89 std::function<absl::StatusOr<std::string>(const std::string&)> diff_proposal;
90 std::function<absl::Status(const std::string&)> accept_proposal;
91 std::function<absl::Status(const std::string&)> reject_proposal;
92 std::function<absl::StatusOr<std::vector<std::string>>()> list_proposals;
93 };
94
95 // ROM Sync Callbacks
97 std::function<absl::StatusOr<std::string>()> generate_rom_diff;
98 std::function<absl::Status(const std::string&, const std::string&)> apply_rom_diff;
99 std::function<std::string()> get_rom_hash;
100 };
101
103
104 // Screenshot preview and region selection
105 void LoadScreenshotPreview(const std::filesystem::path& image_path);
112
113 void SetToastManager(ToastManager* toast_manager);
114
115 void SetProposalDrawer(ProposalDrawer* drawer);
116
118
120 collaboration_callbacks_ = callbacks;
121 }
122
123 void SetMultimodalCallbacks(const MultimodalCallbacks& callbacks);
124 void SetAutomationCallbacks(const AutomationCallbacks& callbacks);
125
126 void UpdateHarnessTelemetry(const AutomationTelemetry& telemetry);
127 void SetLastPlanSummary(const std::string& summary);
128
129 // Automation status polling
132
134 z3ed_callbacks_ = callbacks;
135 }
136
137 void SetRomSyncCallbacks(const RomSyncCallbacks& callbacks) {
138 rom_sync_callbacks_ = callbacks;
139 }
140
141 bool* active() { return &active_; }
142 bool is_active() const { return active_; }
143 void set_active(bool active) { active_ = active; }
144
145public:
146 enum class CollaborationMode {
147 kLocal = 0, // Filesystem-based collaboration
148 kNetwork = 1 // WebSocket-based collaboration
149 };
150
152 bool active = false;
154 std::string session_id;
155 std::string session_name;
156 std::string server_url = "ws://localhost:8765";
157 bool server_connected = false;
158 std::vector<std::string> participants;
159 absl::Time last_synced = absl::InfinitePast();
160 };
161
162 enum class CaptureMode {
163 kFullWindow = 0,
164 kActiveEditor = 1,
165 kSpecificWindow = 2,
166 kRegionSelect = 3 // New: drag to select region
167 };
168
170 void* texture_id = nullptr; // ImTextureID
171 int width = 0;
172 int height = 0;
173 bool loaded = false;
174 float preview_scale = 1.0f;
175 bool show_preview = true;
176 };
177
179 bool active = false;
180 bool dragging = false;
181 ImVec2 start_pos;
182 ImVec2 end_pos;
185 };
186
196
198 std::vector<AutomationTelemetry> recent_tests;
199 bool harness_connected = false;
200 absl::Time last_poll = absl::InfinitePast();
203 float pulse_animation = 0.0f;
204 float scanline_offset = 0.0f;
206 absl::Time last_connection_attempt = absl::InfinitePast();
207 std::string grpc_server_address = "localhost:50052";
208 };
209
210 // Agent Configuration State
212 std::string ai_provider = "mock"; // mock, ollama, gemini
213 std::string ai_model;
214 std::string ollama_host = "http://localhost:11434";
215 std::string gemini_api_key;
216 bool verbose = false;
217 bool show_reasoning = true;
220 char provider_buffer[32] = "mock";
221 char model_buffer[128] = {};
222 char ollama_host_buffer[256] = "http://localhost:11434";
223 char gemini_key_buffer[256] = {};
224 };
225
226 // ROM Sync State
228 std::string current_rom_hash;
229 absl::Time last_sync_time = absl::InfinitePast();
230 bool auto_sync_enabled = false;
232 std::vector<std::string> pending_syncs;
233 };
234
235 // Z3ED Command State
237 std::string last_command;
238 std::string command_output;
239 bool command_running = false;
240 char command_input_buffer[512] = {};
241 };
242
245
246 // Accessors for capture settings
248 const char* specific_window_name() const {
250 }
251
252 // Agent configuration accessors
254 void UpdateAgentConfig(const AgentConfigState& config);
255
256 // Load agent settings from project
259
260 // Collaboration history management (public so EditorManager can call them)
261 void SwitchToSharedHistory(const std::string& session_id);
263
264 // File editing
265 void OpenFileInEditor(const std::string& filepath);
266 void CreateNewFileInEditor(const std::string& filename);
267
268 private:
269 void EnsureHistoryLoaded();
270 void PersistHistory();
271 void RenderHistory();
272 void RenderMessage(const cli::agent::ChatMessage& msg, int index);
274 int index);
275 void RenderInputBox();
277 const absl::StatusOr<cli::agent::ChatMessage>& response);
278 int CountKnownProposals() const;
279 void FocusProposalDrawer(const std::string& proposal_id);
281 int new_total_proposals);
287 void RenderRomSyncPanel();
289 void RenderHarnessPanel();
294 const CollaborationCallbacks::SessionContext& context,
295 bool update_action_timestamp);
296 void MarkHistoryDirty();
297 void PollSharedHistory(); // For real-time collaboration sync
298 void HandleRomSyncReceived(const std::string& diff_data, const std::string& rom_hash);
299 void HandleSnapshotReceived(const std::string& snapshot_data, const std::string& snapshot_type);
300 void HandleProposalReceived(const std::string& proposal_data);
301
302 // History synchronization
303 void SyncHistoryToPopup();
304
305 // AI response state
308 std::string pending_message_;
309
310 // Chat session management
311 struct ChatSession {
312 std::string id;
313 std::string name;
314 std::filesystem::path save_path;
317 bool history_loaded = false;
318 bool history_dirty = false;
319 std::filesystem::path history_path;
320 absl::Time created_at = absl::Now();
321 absl::Time last_persist_time = absl::InfinitePast();
322
323 ChatSession(const std::string& session_id, const std::string& session_name)
324 : id(session_id), name(session_name) {}
325 };
326
327 void SaveChatSession(const ChatSession& session);
328 void LoadChatSession(const std::string& session_id);
329 void DeleteChatSession(const std::string& session_id);
330 std::vector<std::string> GetSavedSessions();
331 std::filesystem::path GetSessionsDirectory();
332
333 std::vector<ChatSession> chat_sessions_;
335
336 // Legacy single session support (will migrate to sessions)
338 char input_buffer_[1024];
339 bool active_ = false;
340 std::string title_;
342 bool history_loaded_ = false;
343 bool history_dirty_ = false;
346 std::filesystem::path history_path_;
352 absl::Time last_persist_time_ = absl::InfinitePast();
353
354 // Main state
361
362 // Callbacks
368
369 // Input buffers
370 char session_name_buffer_[64] = {};
371 char join_code_buffer_[64] = {};
372 char server_url_buffer_[256] = "ws://localhost:8765";
374
375 // Timing
376 absl::Time last_collaboration_action_ = absl::InfinitePast();
377 absl::Time last_shared_history_poll_ = absl::InfinitePast();
379
380 // UI state
381 int active_tab_ = 0; // 0=Chat, 1=Config, 2=Commands, 3=Collab, 4=ROM Sync, 5=Files, 6=Prompt
382 bool show_agent_config_ = false;
385 bool show_rom_sync_ = false;
387 std::vector<uint8_t> snapshot_preview_data_;
388
389 // Reactive UI colors
390 ImVec4 collaboration_status_color_ = ImVec4(0.6f, 0.6f, 0.6f, 1.0f);
391
392 // File editing state
394 std::string filepath;
395 std::string filename;
397 bool modified = false;
398 bool is_system_prompt = false;
399 };
400 std::vector<FileEditorTab> open_files_;
402};
403
404} // namespace editor
405} // namespace yaze
406
407#endif // YAZE_APP_EDITOR_AGENT_AGENT_CHAT_WIDGET_H_
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
ImGui popup drawer for displaying chat history on the left side.
Modern AI chat widget with comprehensive z3ed and yaze-server integration.
Z3EDCommandCallbacks z3ed_callbacks_
void RenderProposalQuickActions(const cli::agent::ChatMessage &msg, int index)
std::vector< std::string > GetSavedSessions()
void SetLastPlanSummary(const std::string &summary)
void RenderMessage(const cli::agent::ChatMessage &msg, int index)
void SaveAgentSettingsToProject(core::YazeProject &project)
void SetMultimodalCallbacks(const MultimodalCallbacks &callbacks)
void SetAutomationCallbacks(const AutomationCallbacks &callbacks)
void LoadAgentSettingsFromProject(const core::YazeProject &project)
cli::agent::PromptMode GetPromptMode() const
const AgentConfigState & GetAgentConfig() const
void CreateNewFileInEditor(const std::string &filename)
void NotifyProposalCreated(const cli::agent::ChatMessage &msg, int new_total_proposals)
std::vector< ChatSession > chat_sessions_
void HandleAgentResponse(const absl::StatusOr< cli::agent::ChatMessage > &response)
cli::agent::PromptMode prompt_mode_
void SetPromptMode(cli::agent::PromptMode mode)
void SaveChatSession(const ChatSession &session)
void SetRomSyncCallbacks(const RomSyncCallbacks &callbacks)
void SetProposalDrawer(ProposalDrawer *drawer)
MultimodalCallbacks multimodal_callbacks_
cli::agent::ConversationalAgentService agent_service_
void FocusProposalDrawer(const std::string &proposal_id)
CollaborationCallbacks collaboration_callbacks_
void SetZ3EDCommandCallbacks(const Z3EDCommandCallbacks &callbacks)
void HandleProposalReceived(const std::string &proposal_data)
void LoadScreenshotPreview(const std::filesystem::path &image_path)
void UpdateAgentConfig(const AgentConfigState &config)
CollaborationState collaboration_state_
void SwitchToSharedHistory(const std::string &session_id)
std::vector< FileEditorTab > open_files_
AutomationCallbacks automation_callbacks_
AgentChatHistoryPopup * chat_history_popup_
std::filesystem::path GetSessionsDirectory()
std::filesystem::path history_path_
void OpenFileInEditor(const std::string &filepath)
void UpdateHarnessTelemetry(const AutomationTelemetry &telemetry)
void SetCollaborationCallbacks(const CollaborationCallbacks &callbacks)
void HandleSnapshotReceived(const std::string &snapshot_data, const std::string &snapshot_type)
void DeleteChatSession(const std::string &session_id)
void SetToastManager(ToastManager *toast_manager)
const char * specific_window_name() const
std::vector< uint8_t > snapshot_preview_data_
void HandleRomSyncReceived(const std::string &diff_data, const std::string &rom_hash)
void ApplyCollaborationSession(const CollaborationCallbacks::SessionContext &context, bool update_action_timestamp)
void SetChatHistoryPopup(AgentChatHistoryPopup *popup)
void LoadChatSession(const std::string &session_id)
ImGui drawer for displaying and managing agent proposals.
Main namespace for the application.
Modern project structure with comprehensive settings consolidation.
Definition project.h:78
std::function< void(const std::string &)> focus_proposal
std::vector< AutomationTelemetry > recent_tests
cli::agent::ConversationalAgentService agent_service
ChatSession(const std::string &session_id, const std::string &session_name)
std::function< absl::StatusOr< SessionContext >()> refresh_session
std::function< absl::StatusOr< SessionContext >(const std::string &)> join_session
std::function< absl::StatusOr< SessionContext >(const std::string &)> host_session
std::function< absl::Status(const std::filesystem::path &, const std::string &)> send_to_gemini
std::function< absl::Status(std::filesystem::path *)> capture_snapshot
std::optional< std::filesystem::path > last_capture_path
std::function< absl::Status(const std::string &, const std::string &)> apply_rom_diff
std::function< absl::StatusOr< std::string >()> generate_rom_diff
std::function< absl::StatusOr< std::string >(const std::string &)> diff_proposal
std::function< absl::StatusOr< std::string >(const std::string &)> plan_agent_task
std::function< absl::StatusOr< std::vector< std::string > >()> list_proposals
std::function< absl::Status(const std::string &)> run_agent_task
std::function< absl::Status(const std::string &)> accept_proposal
std::function< absl::Status(const std::string &)> reject_proposal