yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
chat_tui.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_TUI_CHAT_TUI_H_
2#define YAZE_SRC_CLI_TUI_CHAT_TUI_H_
3
4// FTXUI is not available on WASM builds
5#ifndef __EMSCRIPTEN__
6
7#if defined(YAZE_ENABLE_AGENT_CLI)
8#include <atomic>
9#include <chrono>
10#include <future>
11#include <mutex>
12#include <optional>
13#include <thread>
14#include <vector>
15
19#include "ftxui/component/component.hpp"
20#include "ftxui/component/screen_interactive.hpp"
21#endif
22
23namespace yaze {
24
25class Rom;
26
27namespace cli {
28namespace tui {
29
30#if defined(YAZE_ENABLE_AGENT_CLI)
31class ChatTUI {
32 public:
33 explicit ChatTUI(Rom* rom_context = nullptr);
34 ~ChatTUI();
35 void Run();
36 void SetRomContext(Rom* rom_context);
37
38 private:
39 void OnSubmit(const std::string& message);
40 void LaunchAgentPrompt(const std::string& prompt);
41 void CleanupWorkers();
42 void StopSpinner();
43 void InitializeAutocomplete();
44
45 agent::ChatMessage::SessionMetrics CurrentMetrics() const;
46
47 // Popup state
48 void ToggleTodoPopup();
49 ftxui::Component CreateTodoPopup();
50 ftxui::Component BuildShortcutPalette();
51 bool IsPopupOpen() const;
52 void ToggleShortcutPalette();
53
54 ftxui::ScreenInteractive screen_ = ftxui::ScreenInteractive::Fullscreen();
56 agent::TodoManager todo_manager_;
57 Rom* rom_context_ = nullptr;
58 std::optional<std::string> last_error_;
59 AutocompleteEngine autocomplete_engine_;
60 std::string rom_header_;
61
62 std::atomic<bool> agent_busy_{false};
63 std::atomic<bool> spinner_running_{false};
64 std::atomic<int> spinner_index_{0};
65
66 std::vector<std::future<void>> worker_futures_;
67 mutable std::mutex worker_mutex_;
68 std::chrono::steady_clock::time_point last_send_time_{};
69 double last_response_seconds_ = 0.0;
70 std::vector<double> latency_history_;
71
72 std::vector<std::string> quick_actions_;
73
74 std::thread spinner_thread_;
75
76 // Popup state
77 bool todo_popup_visible_ = false;
78 ftxui::Component todo_popup_component_;
79 ftxui::Component shortcut_palette_component_;
80 bool shortcut_palette_visible_ = false;
81 bool todo_manager_ready_ = false;
82};
83#else
84class ChatTUI {
85 public:
86 explicit ChatTUI(Rom* rom_context = nullptr) : rom_context_(rom_context) {}
87 ~ChatTUI() = default;
88 void Run() {}
89 void SetRomContext(Rom* rom_context) { rom_context_ = rom_context; }
90
91 private:
92 Rom* rom_context_ = nullptr;
93};
94#endif
95
96} // namespace tui
97} // namespace cli
98} // namespace yaze
99
100#endif // __EMSCRIPTEN__
101
102#endif // YAZE_SRC_CLI_TUI_CHAT_TUI_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Manages TODO lists for z3ed agent task execution.
ChatTUI(Rom *rom_context=nullptr)
Definition chat_tui.h:86
void SetRomContext(Rom *rom_context)
Definition chat_tui.h:89