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
112AgentEditor::~AgentEditor() = default;
113
115 // Base initialization
117
118 // Register cards with the card registry
120
121 // Register WindowContent instances with WorkspaceWindowManager
123 auto* window_manager = dependencies_.window_manager;
124
125 // Register all agent EditorPanels with callbacks
126 window_manager->RegisterWindowContent(
127 std::make_unique<AgentConfigurationPanel>(
128 [this]() { DrawConfigurationPanel(); }));
129 window_manager->RegisterWindowContent(
130 std::make_unique<AgentStatusPanel>([this]() { DrawStatusPanel(); }));
131 window_manager->RegisterWindowContent(
132 std::make_unique<AgentPromptEditorPanel>(
133 [this]() { DrawPromptEditorPanel(); }));
134 window_manager->RegisterWindowContent(
135 std::make_unique<AgentBotProfilesPanel>(
136 [this]() { DrawBotProfilesPanel(); }));
137 window_manager->RegisterWindowContent(std::make_unique<AgentBuilderPanel>(
138 [this]() { DrawAgentBuilderPanel(); }));
139 window_manager->RegisterWindowContent(
140 std::make_unique<AgentChatPanel>(agent_chat_.get()));
141
142 // Knowledge Base panel (callback set by AgentUiController)
143 window_manager->RegisterWindowContent(
144 std::make_unique<AgentKnowledgeBasePanel>([this]() {
147 } else {
148 ImGui::TextDisabled("Knowledge service not available");
149 ImGui::TextWrapped(
150 "Build with Z3ED_AI=ON to enable the knowledge service.");
151 }
152 }));
153
154 window_manager->RegisterWindowContent(
155 std::make_unique<AgentMesenDebugPanel>(
156 [this]() { DrawMesenDebugPanel(); }));
157
158 window_manager->RegisterWindowContent(
159 std::make_unique<MesenScreenshotEditorPanel>(
160 [this]() { DrawMesenScreenshotPanel(); }));
161
162 window_manager->RegisterWindowContent(
163 std::make_unique<OracleStateLibraryEditorPanel>(
164 [this]() { DrawOracleStatePanel(); }));
165
166 window_manager->RegisterWindowContent(
167 std::make_unique<FeatureFlagEditorEditorPanel>(
168 [this]() { DrawFeatureFlagPanel(); }));
169
170 window_manager->RegisterWindowContent(std::make_unique<ManifestEditorPanel>(
171 [this]() { DrawManifestPanel(); }));
172
173 window_manager->RegisterWindowContent(
174 std::make_unique<SramViewerEditorPanel>(
175 [this]() { DrawSramViewerPanel(); }));
176
177 if (agent_chat_) {
178 agent_chat_->SetPanelOpener(
179 [window_manager](const std::string& panel_id) {
180 if (!panel_id.empty()) {
181 window_manager->OpenWindow(panel_id);
182 }
183 });
184 }
185 }
186
188}
189
193
196 return;
197 }
198 auto& ui = profile_ui_state_;
201 ? "http://localhost:11434"
203 ui.ollama_host_buf);
205 ui.gemini_key_buf);
207 ui.anthropic_key_buf);
209 ui.openai_key_buf);
211 ? "https://api.openai.com"
213 ui.openai_base_buf);
217 ui.tags_buf);
218 ui.dirty = false;
219}
220
222 // Panel descriptors are now auto-created by RegisterWindowContent() calls
223 // in Initialize(). No need for duplicate RegisterPanel() calls here.
224}
225
226absl::Status AgentEditor::Load() {
227 // Load agent configuration from project/settings
228 // Try to load all bot profiles
229 loaded_profiles_.clear();
230 auto profiles_dir = GetProfilesDirectory();
231 if (std::filesystem::exists(profiles_dir)) {
232 for (const auto& entry :
233 std::filesystem::directory_iterator(profiles_dir)) {
234 if (entry.path().extension() == ".json") {
235 std::ifstream file(entry.path());
236 if (file.is_open()) {
237 std::string json_content((std::istreambuf_iterator<char>(file)),
238 std::istreambuf_iterator<char>());
239 auto profile_or = JsonToProfile(json_content);
240 if (profile_or.ok()) {
241 loaded_profiles_.push_back(profile_or.value());
242 }
243 }
244 }
245 }
246 }
247 return absl::OkStatus();
248}
249
250absl::Status AgentEditor::Save() {
251 // Save current profile
252 current_profile_.modified_at = absl::Now();
254}
255
256absl::Status AgentEditor::Update() {
257 if (!active_)
258 return absl::OkStatus();
259
260 // Draw configuration dashboard
262
263 // Chat widget is drawn separately (not here)
264
265 return absl::OkStatus();
266}
267
270 if (agent_chat_) {
271 agent_chat_->SetContext(context_);
272 }
274}
275
277 return agent_chat_ && *agent_chat_->active();
278}
279
280void AgentEditor::SetChatActive(bool active) {
281 if (agent_chat_) {
282 agent_chat_->set_active(active);
283 }
284}
285
289
291 if (agent_chat_) {
292 agent_chat_->set_active(true);
293 }
294}
295
296} // namespace editor
297} // 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:310
EditorDependencies dependencies_
Definition editor.h:316
EditorType type_
Definition editor.h:315
void RegisterWindowContent(std::unique_ptr< WindowContent > window)
Register a WindowContent instance for central drawing.
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:176