yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_knowledge_panel.cc
Go to the documentation of this file.
2
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace editor {
12
14 AgentUIContext* context,
15 cli::agent::LearnedKnowledgeService* knowledge_service,
16 const Callbacks& callbacks, ToastManager* toast_manager) {
17 if (!knowledge_service) {
18 ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.0f, 1.0f),
19 "Knowledge service not available");
20 ImGui::TextWrapped(
21 "The knowledge service is only available when built with Z3ED_AI "
22 "support.");
23 return;
24 }
25
26 // Header with stats
27 RenderStatsSection(knowledge_service);
28
29 ImGui::Separator();
30
31 // Tab bar for different categories
32 if (gui::BeginThemedTabBar("##KnowledgeTabs")) {
33 if (ImGui::BeginTabItem(ICON_MD_SETTINGS " Preferences")) {
34 selected_tab_ = 0;
35 RenderPreferencesTab(knowledge_service, callbacks, toast_manager);
36 ImGui::EndTabItem();
37 }
38
39 if (ImGui::BeginTabItem(ICON_MD_PATTERN " Patterns")) {
40 selected_tab_ = 1;
41 RenderPatternsTab(knowledge_service);
42 ImGui::EndTabItem();
43 }
44
45 if (ImGui::BeginTabItem(ICON_MD_FOLDER " Projects")) {
46 selected_tab_ = 2;
47 RenderProjectsTab(knowledge_service);
48 ImGui::EndTabItem();
49 }
50
51 if (ImGui::BeginTabItem(ICON_MD_PSYCHOLOGY " Memories")) {
52 selected_tab_ = 3;
53 RenderMemoriesTab(knowledge_service);
54 ImGui::EndTabItem();
55 }
56
58 }
59
60 ImGui::Separator();
61
62 // Action buttons
63 if (ImGui::Button(ICON_MD_REFRESH " Refresh")) {
64 if (callbacks.refresh_knowledge) {
65 callbacks.refresh_knowledge();
66 }
67 }
68
69 ImGui::SameLine();
70
71 if (ImGui::Button(ICON_MD_UPLOAD " Export")) {
72 if (callbacks.export_knowledge) {
73 callbacks.export_knowledge();
74 }
75 }
76
77 ImGui::SameLine();
78
79 {
80 gui::StyleColorGuard clear_guard(ImGuiCol_Button,
81 ImVec4(0.6f, 0.2f, 0.2f, 1.0f));
82 if (ImGui::Button(ICON_MD_DELETE_FOREVER " Clear All")) {
83 ImGui::OpenPopup("Confirm Clear");
84 }
85 }
86
87 // Confirm clear popup
88 if (ImGui::BeginPopupModal("Confirm Clear", nullptr,
89 ImGuiWindowFlags_AlwaysAutoResize)) {
90 ImGui::Text("Clear all learned knowledge?");
91 ImGui::Text("This action cannot be undone.");
92 ImGui::Separator();
93
94 if (ImGui::Button("Yes, Clear All", ImVec2(120, 0))) {
95 if (callbacks.clear_all_knowledge) {
96 callbacks.clear_all_knowledge();
97 }
98 ImGui::CloseCurrentPopup();
99 }
100 ImGui::SameLine();
101 if (ImGui::Button("Cancel", ImVec2(120, 0))) {
102 ImGui::CloseCurrentPopup();
103 }
104 ImGui::EndPopup();
105 }
106}
107
110 auto stats = service->GetStats();
111
112 auto& theme = AgentUI::GetTheme();
113
114 gui::StyledChild stats_child("##StatsSection", ImVec2(0, 60),
115 {.bg = theme.panel_bg_color}, true);
116
117 // Stats row
118 float column_width = ImGui::GetContentRegionAvail().x / 4;
119
120 ImGui::Columns(4, "##StatsColumns", false);
121 ImGui::SetColumnWidth(0, column_width);
122 ImGui::SetColumnWidth(1, column_width);
123 ImGui::SetColumnWidth(2, column_width);
124 ImGui::SetColumnWidth(3, column_width);
125
126 ImGui::TextColored(theme.accent_color, "%d", stats.preference_count);
127 ImGui::Text("Preferences");
128 ImGui::NextColumn();
129
130 ImGui::TextColored(theme.accent_color, "%d", stats.pattern_count);
131 ImGui::Text("Patterns");
132 ImGui::NextColumn();
133
134 ImGui::TextColored(theme.accent_color, "%d", stats.project_count);
135 ImGui::Text("Projects");
136 ImGui::NextColumn();
137
138 ImGui::TextColored(theme.accent_color, "%d", stats.memory_count);
139 ImGui::Text("Memories");
140 ImGui::NextColumn();
141
142 ImGui::Columns(1);
143}
144
146 cli::agent::LearnedKnowledgeService* service, const Callbacks& callbacks,
147 ToastManager* /*toast_manager*/) {
148 // Add new preference
149 ImGui::Text("Add Preference:");
150 ImGui::PushItemWidth(150);
151 ImGui::InputText("##PrefKey", new_pref_key_, sizeof(new_pref_key_));
152 ImGui::PopItemWidth();
153 ImGui::SameLine();
154 ImGui::PushItemWidth(200);
155 ImGui::InputText("##PrefValue", new_pref_value_, sizeof(new_pref_value_));
156 ImGui::PopItemWidth();
157 ImGui::SameLine();
158 if (ImGui::Button(ICON_MD_ADD " Add")) {
159 if (strlen(new_pref_key_) > 0 && strlen(new_pref_value_) > 0) {
160 if (callbacks.set_preference) {
162 }
163 new_pref_key_[0] = '\0';
164 new_pref_value_[0] = '\0';
165 }
166 }
167
168 ImGui::Separator();
169
170 // List existing preferences
171 auto prefs = service->GetAllPreferences();
172 if (prefs.empty()) {
173 ImGui::TextDisabled("No preferences stored");
174 } else {
175 ImGui::BeginChild("##PrefsList", ImVec2(0, 0), true);
176 for (const auto& [key, value] : prefs) {
177 ImGui::PushID(key.c_str());
178
179 // Key column
180 ImGui::TextColored(ImVec4(0.7f, 0.9f, 1.0f, 1.0f), "%s", key.c_str());
181 ImGui::SameLine(200);
182
183 // Value column
184 ImGui::TextWrapped("%s", value.c_str());
185 ImGui::SameLine(ImGui::GetContentRegionAvail().x - 30);
186
187 // Delete button
188 if (ImGui::SmallButton(ICON_MD_DELETE)) {
189 if (callbacks.remove_preference) {
190 callbacks.remove_preference(key);
191 }
192 }
193
194 ImGui::PopID();
195 ImGui::Separator();
196 }
197 ImGui::EndChild();
198 }
199}
200
203 auto patterns = service->QueryPatterns("");
204
205 if (patterns.empty()) {
206 ImGui::TextDisabled("No patterns learned yet");
207 ImGui::TextWrapped(
208 "Patterns are learned automatically as you work with ROMs. "
209 "The agent remembers frequently accessed rooms, sprite "
210 "distributions, and tile usage patterns.");
211 return;
212 }
213
214 ImGui::BeginChild("##PatternsList", ImVec2(0, 0), true);
215 for (size_t i = 0; i < patterns.size(); ++i) {
216 const auto& pattern = patterns[i];
217 ImGui::PushID(static_cast<int>(i));
218
219 // Pattern type header
220 bool open = ImGui::TreeNode("##Pattern", "%s %s", ICON_MD_PATTERN,
221 pattern.pattern_type.c_str());
222
223 if (open) {
224 ImGui::TextDisabled("ROM Hash: %s...",
225 pattern.rom_hash.substr(0, 16).c_str());
226 ImGui::TextDisabled("Confidence: %.0f%%", pattern.confidence * 100);
227 ImGui::TextDisabled("Access Count: %d", pattern.access_count);
228
229 // Show truncated data
230 if (pattern.pattern_data.size() > 100) {
231 ImGui::TextWrapped("Data: %s...",
232 pattern.pattern_data.substr(0, 100).c_str());
233 } else {
234 ImGui::TextWrapped("Data: %s", pattern.pattern_data.c_str());
235 }
236
237 ImGui::TreePop();
238 }
239
240 ImGui::PopID();
241 }
242 ImGui::EndChild();
243}
244
247 auto projects = service->GetAllProjects();
248
249 if (projects.empty()) {
250 ImGui::TextDisabled("No project contexts saved");
251 ImGui::TextWrapped(
252 "Project contexts store ROM-specific notes, goals, and custom labels. "
253 "They're saved automatically when working with a project.");
254 return;
255 }
256
257 ImGui::BeginChild("##ProjectsList", ImVec2(0, 0), true);
258 for (size_t i = 0; i < projects.size(); ++i) {
259 const auto& project = projects[i];
260 ImGui::PushID(static_cast<int>(i));
261
262 bool open = ImGui::TreeNode("##Project", "%s %s", ICON_MD_FOLDER,
263 project.project_name.c_str());
264
265 if (open) {
266 ImGui::TextDisabled("ROM Hash: %s...",
267 project.rom_hash.substr(0, 16).c_str());
268
269 // Show truncated context
270 if (project.context_data.size() > 200) {
271 ImGui::TextWrapped("Context: %s...",
272 project.context_data.substr(0, 200).c_str());
273 } else {
274 ImGui::TextWrapped("Context: %s", project.context_data.c_str());
275 }
276
277 ImGui::TreePop();
278 }
279
280 ImGui::PopID();
281 }
282 ImGui::EndChild();
283}
284
287 // Search bar
288 ImGui::Text("Search:");
289 ImGui::SameLine();
290 ImGui::PushItemWidth(300);
291 bool search_changed =
292 ImGui::InputText("##MemSearch", memory_search_, sizeof(memory_search_));
293 ImGui::PopItemWidth();
294
295 ImGui::Separator();
296
297 // Get memories (search or recent)
298 std::vector<cli::agent::LearnedKnowledgeService::ConversationMemory> memories;
299 if (strlen(memory_search_) > 0) {
300 memories = service->SearchMemories(memory_search_);
301 } else {
302 memories = service->GetRecentMemories(20);
303 }
304
305 if (memories.empty()) {
306 if (strlen(memory_search_) > 0) {
307 ImGui::TextDisabled("No memories match '%s'", memory_search_);
308 } else {
309 ImGui::TextDisabled("No conversation memories stored");
310 ImGui::TextWrapped(
311 "Conversation memories are summaries of past discussions with the "
312 "agent. They help maintain context across sessions.");
313 }
314 return;
315 }
316
317 ImGui::BeginChild("##MemoriesList", ImVec2(0, 0), true);
318 for (size_t i = 0; i < memories.size(); ++i) {
319 const auto& memory = memories[i];
320 ImGui::PushID(static_cast<int>(i));
321
322 bool open = ImGui::TreeNode("##Memory", "%s %s", ICON_MD_PSYCHOLOGY,
323 memory.topic.c_str());
324
325 if (open) {
326 ImGui::TextWrapped("%s", memory.summary.c_str());
327
328 if (!memory.key_facts.empty()) {
329 ImGui::Text("Key Facts:");
330 for (const auto& fact : memory.key_facts) {
331 ImGui::BulletText("%s", fact.c_str());
332 }
333 }
334
335 ImGui::TextDisabled("Access Count: %d", memory.access_count);
336
337 ImGui::TreePop();
338 }
339
340 ImGui::PopID();
341 }
342 ImGui::EndChild();
343}
344
345} // namespace editor
346} // namespace yaze
Manages persistent learned information across agent sessions.
std::vector< ProjectContext > GetAllProjects() const
std::vector< ConversationMemory > GetRecentMemories(int limit=10) const
std::vector< ConversationMemory > SearchMemories(const std::string &query) const
std::vector< ROMPattern > QueryPatterns(const std::string &type, const std::string &rom_hash="") const
std::map< std::string, std::string > GetAllPreferences() const
void RenderStatsSection(cli::agent::LearnedKnowledgeService *service)
void RenderPreferencesTab(cli::agent::LearnedKnowledgeService *service, const Callbacks &callbacks, ToastManager *toast_manager)
void RenderPatternsTab(cli::agent::LearnedKnowledgeService *service)
void Draw(AgentUIContext *context, cli::agent::LearnedKnowledgeService *knowledge_service, const Callbacks &callbacks, ToastManager *toast_manager)
void RenderProjectsTab(cli::agent::LearnedKnowledgeService *service)
void RenderMemoriesTab(cli::agent::LearnedKnowledgeService *service)
Unified context for agent UI components.
RAII guard for ImGui style colors.
Definition style_guard.h:27
RAII guard for ImGui child windows with optional styling.
#define ICON_MD_SETTINGS
Definition icons.h:1699
#define ICON_MD_REFRESH
Definition icons.h:1572
#define ICON_MD_UPLOAD
Definition icons.h:2048
#define ICON_MD_ADD
Definition icons.h:86
#define ICON_MD_PSYCHOLOGY
Definition icons.h:1523
#define ICON_MD_DELETE
Definition icons.h:530
#define ICON_MD_FOLDER
Definition icons.h:809
#define ICON_MD_DELETE_FOREVER
Definition icons.h:531
#define ICON_MD_PATTERN
Definition icons.h:1388
const AgentUITheme & GetTheme()
bool BeginThemedTabBar(const char *id, ImGuiTabBarFlags flags)
A stylized tab bar with "Mission Control" branding.
void EndThemedTabBar()
std::function< void(const std::string &) remove_preference)
std::function< void(const std::string &, const std::string &) set_preference)