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