yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_editor.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <filesystem>
5#include <fstream>
6#include <memory>
7
10// Centralized UI theme
11#include "app/gui/style/theme.h"
12
15
16#include "absl/strings/str_format.h"
17#include "absl/time/clock.h"
18#include "absl/time/time.h"
30#include "app/gui/core/icons.h"
36#include "rom/rom.h"
37#include "util/file_util.h"
38
39#ifdef YAZE_WITH_GRPC
41#endif
42
43namespace yaze {
44namespace editor {
45
46namespace {
47std::string BuildTagsString(const std::vector<std::string>& tags) {
48 std::string result;
49 for (size_t i = 0; i < tags.size(); ++i) {
50 if (i > 0) {
51 result.append(", ");
52 }
53 result.append(tags[i]);
54 }
55 return result;
56}
57
58} // namespace
59
62 agent_chat_ = std::make_unique<AgentChat>();
63 local_coordinator_ = std::make_unique<AgentCollaborationCoordinator>();
64 config_panel_ = std::make_unique<AgentConfigPanel>();
65 feature_flag_panel_ = std::make_unique<FeatureFlagEditorPanel>();
66 manifest_panel_ = std::make_unique<ManifestPanel>();
67 mesen_debug_panel_ = std::make_unique<MesenDebugPanel>();
68 mesen_screenshot_panel_ = std::make_unique<MesenScreenshotPanel>();
69 oracle_state_panel_ = std::make_unique<OracleStateLibraryPanel>();
70 sram_viewer_panel_ = std::make_unique<SramViewerPanel>();
71 prompt_editor_ = std::make_unique<TextEditor>();
72 common_tiles_editor_ = std::make_unique<TextEditor>();
73
74 // Initialize default configuration (legacy)
78
79 // Initialize default bot profile
80 current_profile_.name = "Default Z3ED Bot";
81 current_profile_.description = "Default bot for Zelda 3 ROM editing";
86 current_profile_.tags = {"default", "z3ed"};
87
88 // Setup text editors
89 prompt_editor_->SetLanguageDefinition(
91 prompt_editor_->SetReadOnly(false);
92 prompt_editor_->SetShowWhitespaces(false);
93
94 common_tiles_editor_->SetLanguageDefinition(
96 common_tiles_editor_->SetReadOnly(false);
97 common_tiles_editor_->SetShowWhitespaces(false);
98
99 // Ensure profiles directory exists
101
103 {"Persona", "Define persona and goals", false},
104 {"Tool Stack", "Select the agent's tools", false},
105 {"Automation", "Configure automation hooks", false},
106 {"Validation", "Describe E2E validation", false},
107 {"E2E Checklist", "Track readiness for end-to-end runs", false}};
109 "Describe the persona, tone, and constraints for this agent.";
110}
111
113#ifdef YAZE_WITH_GRPC
114 if (harness_telemetry_bridge_) {
115 harness_telemetry_bridge_->SetAgentChat(nullptr);
116 test::TestManager::Get().ClearHarnessListener(
117 harness_telemetry_bridge_.get());
118 harness_telemetry_bridge_.reset();
119 }
120#endif
121}
122
124 // Base initialization
126
127 // Register cards with the card registry
129
130 // Register WindowContent instances with WorkspaceWindowManager
132 auto* window_manager = dependencies_.window_manager;
133
134 // Register all agent EditorPanels with callbacks
135 window_manager->RegisterWindowContent(
136 std::make_unique<AgentConfigurationPanel>(
137 [this]() { DrawConfigurationPanel(); }));
138 window_manager->RegisterWindowContent(
139 std::make_unique<AgentStatusPanel>([this]() { DrawStatusPanel(); }));
140 window_manager->RegisterWindowContent(
141 std::make_unique<AgentPromptEditorPanel>(
142 [this]() { DrawPromptEditorPanel(); }));
143 window_manager->RegisterWindowContent(
144 std::make_unique<AgentBotProfilesPanel>(
145 [this]() { DrawBotProfilesPanel(); }));
146 window_manager->RegisterWindowContent(std::make_unique<AgentBuilderPanel>(
147 [this]() { DrawAgentBuilderPanel(); }));
148 window_manager->RegisterWindowContent(
149 std::make_unique<AgentChatPanel>(agent_chat_.get()));
150
151 // Knowledge Base panel (callback set by AgentUiController)
152 window_manager->RegisterWindowContent(
153 std::make_unique<AgentKnowledgeBasePanel>([this]() {
156 } else {
157 ImGui::TextDisabled("Knowledge service not available");
158 ImGui::TextWrapped(
159 "Build with Z3ED_AI=ON to enable the knowledge service.");
160 }
161 }));
162
163 window_manager->RegisterWindowContent(
164 std::make_unique<AgentMesenDebugPanel>(
165 [this]() { DrawMesenDebugPanel(); }));
166
167 window_manager->RegisterWindowContent(
168 std::make_unique<MesenScreenshotEditorPanel>(
169 [this]() { DrawMesenScreenshotPanel(); }));
170
171 window_manager->RegisterWindowContent(
172 std::make_unique<OracleStateLibraryEditorPanel>(
173 [this]() { DrawOracleStatePanel(); }));
174
175 window_manager->RegisterWindowContent(
176 std::make_unique<FeatureFlagEditorEditorPanel>(
177 [this]() { DrawFeatureFlagPanel(); }));
178
179 window_manager->RegisterWindowContent(std::make_unique<ManifestEditorPanel>(
180 [this]() { DrawManifestPanel(); }));
181
182 window_manager->RegisterWindowContent(
183 std::make_unique<SramViewerEditorPanel>(
184 [this]() { DrawSramViewerPanel(); }));
185
186 if (agent_chat_) {
187 agent_chat_->SetPanelOpener(
188 [window_manager](const std::string& panel_id) {
189 if (!panel_id.empty()) {
190 window_manager->OpenWindow(panel_id);
191 }
192 });
193 }
194 }
195
197}
198
202
205 return;
206 }
207 auto& ui = profile_ui_state_;
210 ? "http://localhost:11434"
212 ui.ollama_host_buf);
214 ui.gemini_key_buf);
216 ui.anthropic_key_buf);
218 ui.openai_key_buf);
220 ? "https://api.openai.com"
222 ui.openai_base_buf);
226 ui.tags_buf);
227 ui.dirty = false;
228}
229
231 // Panel descriptors are now auto-created by RegisterWindowContent() calls
232 // in Initialize(). No need for duplicate RegisterPanel() calls here.
233}
234
235absl::Status AgentEditor::Load() {
236 // Load agent configuration from project/settings
237 // Try to load all bot profiles
238 loaded_profiles_.clear();
239 auto profiles_dir = GetProfilesDirectory();
240 if (std::filesystem::exists(profiles_dir)) {
241 for (const auto& entry :
242 std::filesystem::directory_iterator(profiles_dir)) {
243 if (entry.path().extension() == ".json") {
244 std::ifstream file(entry.path());
245 if (file.is_open()) {
246 std::string json_content((std::istreambuf_iterator<char>(file)),
247 std::istreambuf_iterator<char>());
248 auto profile_or = JsonToProfile(json_content);
249 if (profile_or.ok()) {
250 loaded_profiles_.push_back(profile_or.value());
251 }
252 }
253 }
254 }
255 }
256 return absl::OkStatus();
257}
258
259absl::Status AgentEditor::Save() {
260 // Save current profile
261 current_profile_.modified_at = absl::Now();
263}
264
265absl::Status AgentEditor::Update() {
266 if (!active_)
267 return absl::OkStatus();
268
269 // Draw configuration dashboard
271
272 // Chat widget is drawn separately (not here)
273
274 return absl::OkStatus();
275}
276
279 if (agent_chat_) {
280 agent_chat_->SetContext(context_);
281 }
283}
284
286 return agent_chat_ && *agent_chat_->active();
287}
288
289void AgentEditor::SetChatActive(bool active) {
290 if (agent_chat_) {
291 agent_chat_->set_active(active);
292 }
293}
294
298
300 if (agent_chat_) {
301 agent_chat_->set_active(true);
302 }
303}
304
305} // namespace editor
306} // namespace yaze
void SetChatActive(bool active)
std::unique_ptr< MesenScreenshotPanel > mesen_screenshot_panel_
KnowledgePanelCallback knowledge_panel_callback_
absl::StatusOr< BotProfile > JsonToProfile(const std::string &json) const
std::unique_ptr< OracleStateLibraryPanel > oracle_state_panel_
AgentBuilderState builder_state_
absl::Status Save() override
std::unique_ptr< FeatureFlagEditorPanel > feature_flag_panel_
std::unique_ptr< AgentConfigPanel > config_panel_
void SetContext(AgentUIContext *context)
std::unique_ptr< MesenDebugPanel > mesen_debug_panel_
AgentUIContext * context_
ProfileUiState profile_ui_state_
absl::Status SaveBotProfile(const BotProfile &profile)
std::filesystem::path GetProfilesDirectory() const
std::unique_ptr< TextEditor > common_tiles_editor_
std::unique_ptr< TextEditor > prompt_editor_
std::unique_ptr< AgentCollaborationCoordinator > local_coordinator_
std::unique_ptr< SramViewerPanel > sram_viewer_panel_
absl::Status Load() override
std::unique_ptr< AgentChat > agent_chat_
absl::Status Update() override
void ApplyUserSettingsDefaults(bool force=false)
std::unique_ptr< ManifestPanel > manifest_panel_
std::vector< BotProfile > loaded_profiles_
Unified context for agent UI components.
EditorContext context() const
Definition editor.h:327
EditorDependencies dependencies_
Definition editor.h:333
EditorType type_
Definition editor.h:332
void RegisterWindowContent(std::unique_ptr< WindowContent > window)
Register a WindowContent instance for central drawing.
static TestManager & Get()
constexpr char kProviderMock[]
Definition provider_ids.h:7
std::string BuildTagsString(const std::vector< std::string > &tags)
void CopyStringToBuffer(const std::string &src, char(&dest)[N])
static const LanguageDefinition & CPlusPlus()
std::vector< std::string > tags
WorkspaceWindowManager * window_manager
Definition editor.h:181