6#include "imgui/imgui.h"
15 if (!knowledge_service) {
16 ImGui::TextColored(ImVec4(1.0f, 0.5f, 0.0f, 1.0f),
17 "Knowledge service not available");
19 "The knowledge service is only available when built with Z3ED_AI "
30 if (ImGui::BeginTabBar(
"##KnowledgeTabs")) {
77 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.6f, 0.2f, 0.2f, 1.0f));
79 ImGui::OpenPopup(
"Confirm Clear");
81 ImGui::PopStyleColor();
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.");
90 if (ImGui::Button(
"Yes, Clear All", ImVec2(120, 0))) {
94 ImGui::CloseCurrentPopup();
97 if (ImGui::Button(
"Cancel", ImVec2(120, 0))) {
98 ImGui::CloseCurrentPopup();
110 ImGui::PushStyleColor(ImGuiCol_ChildBg, theme.panel_bg_color);
111 ImGui::BeginChild(
"##StatsSection", ImVec2(0, 60),
true);
114 float column_width = ImGui::GetContentRegionAvail().x / 4;
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);
122 ImGui::TextColored(theme.accent_color,
"%d", stats.preference_count);
123 ImGui::Text(
"Preferences");
126 ImGui::TextColored(theme.accent_color,
"%d", stats.pattern_count);
127 ImGui::Text(
"Patterns");
130 ImGui::TextColored(theme.accent_color,
"%d", stats.project_count);
131 ImGui::Text(
"Projects");
134 ImGui::TextColored(theme.accent_color,
"%d", stats.memory_count);
135 ImGui::Text(
"Memories");
141 ImGui::PopStyleColor();
148 ImGui::Text(
"Add Preference:");
149 ImGui::PushItemWidth(150);
151 ImGui::PopItemWidth();
153 ImGui::PushItemWidth(200);
155 ImGui::PopItemWidth();
172 ImGui::TextDisabled(
"No preferences stored");
174 ImGui::BeginChild(
"##PrefsList", ImVec2(0, 0),
true);
175 for (
const auto& [key, value] : prefs) {
176 ImGui::PushID(key.c_str());
179 ImGui::TextColored(ImVec4(0.7f, 0.9f, 1.0f, 1.0f),
"%s", key.c_str());
180 ImGui::SameLine(200);
183 ImGui::TextWrapped(
"%s", value.c_str());
184 ImGui::SameLine(ImGui::GetContentRegionAvail().x - 30);
204 if (patterns.empty()) {
205 ImGui::TextDisabled(
"No patterns learned yet");
207 "Patterns are learned automatically as you work with ROMs. "
208 "The agent remembers frequently accessed rooms, sprite "
209 "distributions, and tile usage patterns.");
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));
220 ImGui::TreeNode(
"##Pattern",
"%s %s",
ICON_MD_PATTERN, pattern.pattern_type.c_str());
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);
229 if (pattern.pattern_data.size() > 100) {
230 ImGui::TextWrapped(
"Data: %s...",
231 pattern.pattern_data.substr(0, 100).c_str());
233 ImGui::TextWrapped(
"Data: %s", pattern.pattern_data.c_str());
248 if (projects.empty()) {
249 ImGui::TextDisabled(
"No project contexts saved");
251 "Project contexts store ROM-specific notes, goals, and custom labels. "
252 "They're saved automatically when working with a project.");
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));
262 project.project_name.c_str());
265 ImGui::TextDisabled(
"ROM Hash: %s...",
266 project.rom_hash.substr(0, 16).c_str());
269 if (project.context_data.size() > 200) {
270 ImGui::TextWrapped(
"Context: %s...",
271 project.context_data.substr(0, 200).c_str());
273 ImGui::TextWrapped(
"Context: %s", project.context_data.c_str());
287 ImGui::Text(
"Search:");
289 ImGui::PushItemWidth(300);
290 bool search_changed =
292 ImGui::PopItemWidth();
297 std::vector<cli::agent::LearnedKnowledgeService::ConversationMemory> memories;
304 if (memories.empty()) {
308 ImGui::TextDisabled(
"No conversation memories stored");
310 "Conversation memories are summaries of past discussions with the "
311 "agent. They help maintain context across sessions.");
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));
322 memory.topic.c_str());
325 ImGui::TextWrapped(
"%s", memory.summary.c_str());
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());
334 ImGui::TextDisabled(
"Access Count: %d", memory.access_count);
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)
char new_pref_value_[256]
Unified context for agent UI components.
#define ICON_MD_PSYCHOLOGY
#define ICON_MD_DELETE_FOREVER
const AgentUITheme & GetTheme()
std::function< void(const std::string &) remove_preference)
std::function< void()> refresh_knowledge
std::function< void()> clear_all_knowledge
std::function< void(const std::string &, const std::string &) set_preference)
std::function< void()> export_knowledge