From 757c96b58ef0dd8758a468fb8a750eb722144ea8 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 11 Mar 2026 21:18:45 -0400 Subject: [PATCH] checkping fixing and refining these preset managers --- src/gui_2.py | 233 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 145 insertions(+), 88 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index ddbbacf..3a10785 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -125,6 +125,7 @@ class App: self._editing_tool_preset_name = '' self._editing_tool_preset_categories = {} self._editing_tool_preset_scope = 'project' + self._selected_preset_idx = -1 self._selected_tool_preset_idx = -1 self._selected_bias_profile_idx = -1 self._new_bias_tool_name = "run_powershell" @@ -137,6 +138,15 @@ class App: self._editing_preset_scope = "project" self._editing_preset_is_new = False self._presets_list: dict[str, dict] = {} + # Layout state + self._persona_split_v = 0.4 + self._persona_models_open = True + self._persona_prompt_open = True + self._tool_split_v = 0.4 + self._bias_split_v = 0.6 + self._tool_list_open = True + self._bias_list_open = True + self._prompt_md_preview = False # Aliases for controller-owned locks self._send_thread_lock = self.controller._send_thread_lock self._disc_entries_lock = self.controller._disc_entries_lock @@ -1075,6 +1085,10 @@ class App: try: self._render_preset_manager_content(is_embedded=is_embedded) + except Exception as e: + import traceback + traceback.print_exc() + imgui.text_colored(vec4(255, 0, 0), f"Error in Prompt Presets Manager: {e}") finally: if not is_embedded: imgui.end() @@ -1082,6 +1096,10 @@ class App: def _render_tool_preset_manager_content(self, is_embedded: bool = False) -> None: avail = imgui.get_content_region_avail() if not hasattr(self, "_tool_split_v"): self._tool_split_v = 0.4 + if not hasattr(self, "_bias_split_v"): self._bias_split_v = 0.6 + if not hasattr(self, "_tool_list_open"): self._tool_list_open = True + if not hasattr(self, "_bias_list_open"): self._bias_list_open = True + try: if imgui.begin_table("tp_main_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v): imgui.table_setup_column("List", imgui.TableColumnFlags_.width_fixed, 200) @@ -1091,7 +1109,7 @@ class App: # Left Sidebar imgui.table_next_column() imgui.begin_child("tp_list_pane", imgui.ImVec2(0, 0), False) - if imgui.button("New Tool Preset", imgui.ImVec2(-1, 0)): + if imgui.button("New Preset", imgui.ImVec2(-1, 0)): self._editing_tool_preset_name = ""; self._editing_tool_preset_categories = {cat: {} for cat in models.DEFAULT_TOOL_CATEGORIES} self._editing_tool_preset_scope = "project"; self._selected_tool_preset_idx = -1 imgui.separator() @@ -1106,7 +1124,7 @@ class App: # Right Editor imgui.table_next_column() avail_r = imgui.get_content_region_avail() - # Leave space for bottom buttons + # Bottom buttons reserved space imgui.begin_child("tp_editor_content", imgui.ImVec2(0, avail_r.y - 45), False) p_name = self._editing_tool_preset_name or "(New Tool Preset)" @@ -1122,12 +1140,19 @@ class App: imgui.end_table() # Vertical split calculation - total_h = imgui.get_content_region_avail().y - 100 - h1 = total_h * self._tool_split_v - h2 = total_h - h1 - 8 + rem_y = imgui.get_content_region_avail().y - 80 + if self._tool_list_open and self._bias_list_open: + h1 = rem_y * self._tool_split_v + h2 = rem_y - h1 - 10 + elif self._tool_list_open: h1, h2 = rem_y, 0 + elif self._bias_list_open: h1, h2 = 0, rem_y + else: h1, h2 = 0, 0 imgui.dummy(imgui.ImVec2(0, 4)) - if imgui.collapsing_header("Categories & Tools", imgui.TreeNodeFlags_.default_open): + opened_tools = imgui.collapsing_header("Categories & Tools", imgui.TreeNodeFlags_.default_open) + if opened_tools != self._tool_list_open: self._tool_list_open = opened_tools + + if self._tool_list_open: imgui.text("Filter:"); imgui.same_line() cat_opts = ["All"] + sorted(list(models.DEFAULT_TOOL_CATEGORIES.keys())) f_idx = cat_opts.index(self.ui_tool_filter_category) if self.ui_tool_filter_category in cat_opts else 0 @@ -1141,7 +1166,7 @@ class App: if cat_name not in self._editing_tool_preset_categories: self._editing_tool_preset_categories[cat_name] = [] curr_cat_tools = self._editing_tool_preset_categories[cat_name] if imgui.begin_table(f"tt_{cat_name}", 2, imgui.TableFlags_.borders_inner_v): - imgui.table_setup_column("Tool", imgui.TableColumnFlags_.width_fixed, 180); imgui.table_setup_column("Ctrls", imgui.TableColumnFlags_.width_stretch) + imgui.table_setup_column("Tool", imgui.TableColumnFlags_.width_fixed, 250); imgui.table_setup_column("Ctrls", imgui.TableColumnFlags_.width_stretch) for tool_name in default_tools: tool = next((t for t in curr_cat_tools if t.name == tool_name), None) mode = "disabled" if tool is None else tool.approval @@ -1165,14 +1190,15 @@ class App: except: pass imgui.end_table(); imgui.tree_pop() imgui.end_child() - - # Vertical Splitter - imgui.button("###tool_splitter", imgui.ImVec2(-1, 4)) - if imgui.is_item_active(): - self._tool_split_v = max(0.1, min(0.9, self._tool_split_v + imgui.get_io().mouse_delta.y / total_h)) + if self._bias_list_open: + imgui.button("###tool_splitter", imgui.ImVec2(-1, 4)) + if imgui.is_item_active(): self._tool_split_v = max(0.1, min(0.9, self._tool_split_v + imgui.get_io().mouse_delta.y / rem_y)) imgui.dummy(imgui.ImVec2(0, 4)) - if imgui.collapsing_header("Bias Profiles", imgui.TreeNodeFlags_.default_open): + opened_bias = imgui.collapsing_header("Bias Profiles", imgui.TreeNodeFlags_.default_open) + if opened_bias != self._bias_list_open: self._bias_list_open = opened_bias + + if self._bias_list_open: imgui.begin_child("bias_area", imgui.ImVec2(0, h2), True) if imgui.begin_table("bias_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v): imgui.table_setup_column("BList", imgui.TableColumnFlags_.width_fixed, 150); imgui.table_setup_column("BEdit", imgui.TableColumnFlags_.width_stretch) @@ -1190,11 +1216,17 @@ class App: imgui.table_next_column() imgui.begin_child("bedit_pane", imgui.ImVec2(0, 0), False) imgui.text("Name:"); imgui.same_line(); imgui.set_next_item_width(-1); _, self._editing_bias_profile_name = imgui.input_text("##bname", self._editing_bias_profile_name) - imgui.text_colored(C_KEY, "Tool Weighting:"); imgui.begin_child("btool_scroll", imgui.ImVec2(0, -120), True) + + # Bias Split: Weights vs Multipliers + rem_bias_y = imgui.get_content_region_avail().y - 40 + bh1 = rem_bias_y * self._bias_split_v + bh2 = rem_bias_y - bh1 - 10 + + imgui.text_colored(C_KEY, "Tool Weights:"); imgui.begin_child("btool_scroll", imgui.ImVec2(0, bh1), True) for cat_name, default_tools in models.DEFAULT_TOOL_CATEGORIES.items(): if imgui.tree_node(f"{cat_name}##b"): if imgui.begin_table(f"bt_{cat_name}", 2): - imgui.table_setup_column("T", imgui.TableColumnFlags_.width_fixed, 220); imgui.table_setup_column("W", imgui.TableColumnFlags_.width_stretch) + imgui.table_setup_column("T", imgui.TableColumnFlags_.width_fixed, 250); imgui.table_setup_column("W", imgui.TableColumnFlags_.width_stretch) for tn in default_tools: imgui.table_next_row(); imgui.table_next_column(); imgui.text(tn); imgui.table_next_column() curr_w = self._editing_bias_profile_tool_weights.get(tn, 3); imgui.set_next_item_width(-1) @@ -1202,15 +1234,20 @@ class App: if ch_w: self._editing_bias_profile_tool_weights[tn] = n_w imgui.end_table(); imgui.tree_pop() imgui.end_child() - imgui.text_colored(C_KEY, "Category Multipliers:"); imgui.begin_child("bcat_scroll", imgui.ImVec2(0, 80), True) + + imgui.button("###bias_splitter", imgui.ImVec2(-1, 4)) + if imgui.is_item_active(): self._bias_split_v = max(0.1, min(0.9, self._bias_split_v + imgui.get_io().mouse_delta.y / rem_bias_y)) + + imgui.text_colored(C_KEY, "Category Multipliers:"); imgui.begin_child("bcat_scroll", imgui.ImVec2(0, bh2), True) if imgui.begin_table("bcats", 2): - imgui.table_setup_column("C", imgui.TableColumnFlags_.width_fixed, 220); imgui.table_setup_column("M", imgui.TableColumnFlags_.width_stretch) + imgui.table_setup_column("C", imgui.TableColumnFlags_.width_fixed, 250); imgui.table_setup_column("M", imgui.TableColumnFlags_.width_stretch) for cn in sorted(models.DEFAULT_TOOL_CATEGORIES.keys()): imgui.table_next_row(); imgui.table_next_column(); imgui.text(cn); imgui.table_next_column() curr_m = self._editing_bias_profile_category_multipliers.get(cn, 1.0); imgui.set_next_item_width(-1) ch_m, n_m = imgui.slider_float(f"##cm_{cn}", curr_m, 0.1, 5.0, "%.1fx"); if ch_m: self._editing_bias_profile_category_multipliers[cn] = n_m imgui.end_table(); imgui.end_child() + if imgui.button("Save Profile", imgui.ImVec2(-1, 0)): try: p = models.BiasProfile(name=self._editing_bias_profile_name, tool_weights=self._editing_bias_profile_tool_weights, category_multipliers=self._editing_bias_profile_category_multipliers) @@ -1220,15 +1257,15 @@ class App: imgui.end_child() imgui.end_child() - # Fixed Bottom Buttons + # --- Footer Buttons --- imgui.separator() - if imgui.button("Save Tool Preset", imgui.ImVec2(150, 0)): - if self._editing_tool_preset_name.strip(): self.controller._cb_save_tool_preset(self._editing_tool_preset_name.strip(), self._editing_tool_preset_categories, self._editing_tool_preset_scope); self.ai_status = f"Saved Preset: {self._editing_tool_preset_name}" + if imgui.button("Save", imgui.ImVec2(100, 0)): + if self._editing_tool_preset_name.strip(): self.controller._cb_save_tool_preset(self._editing_tool_preset_name.strip(), self._editing_tool_preset_categories, self._editing_tool_preset_scope); self.ai_status = f"Saved: {self._editing_tool_preset_name}" imgui.same_line(); - if imgui.button("Delete Preset", imgui.ImVec2(120, 0)): + if imgui.button("Delete", imgui.ImVec2(100, 0)): if self._editing_tool_preset_name: self.controller._cb_delete_tool_preset(self._editing_tool_preset_name, self._editing_tool_preset_scope); self._editing_tool_preset_name = ""; self._selected_tool_preset_idx = -1 - imgui.same_line(); if not is_embedded: + imgui.same_line(); if imgui.button("Close", imgui.ImVec2(100, 0)): self.show_tool_preset_manager_window = False imgui.end_table() finally: @@ -1246,6 +1283,10 @@ class App: try: self._render_tool_preset_manager_content(is_embedded=is_embedded) + except Exception as e: + import traceback + traceback.print_exc() + imgui.text_colored(vec4(255, 0, 0), f"Error in Tool Preset Manager: {e}") finally: if not is_embedded: imgui.end() @@ -1257,14 +1298,13 @@ class App: if not opened: imgui.end(); return - if not hasattr(self, "_persona_split_v"): self._persona_split_v = 0.4 try: if imgui.begin_table("persona_main_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v): imgui.table_setup_column("List", imgui.TableColumnFlags_.width_fixed, 200) imgui.table_setup_column("Editor", imgui.TableColumnFlags_.width_stretch) imgui.table_next_row() - # Left Sidebar + # --- Left Sidebar --- imgui.table_next_column() imgui.begin_child("persona_list_pane", imgui.ImVec2(0, 0), False) if imgui.button("New Persona", imgui.ImVec2(-1, 0)): @@ -1282,15 +1322,15 @@ class App: self._editing_persona_scope = self.controller.persona_manager.get_persona_scope(p.name); self._editing_persona_is_new = False imgui.end_child() - # Right Editor + # --- Right Editor --- imgui.table_next_column() avail = imgui.get_content_region_avail() - # Ensure buttons stay at the absolute bottom - imgui.begin_child("persona_editor_content", imgui.ImVec2(0, avail.y - 40), False) - header = "New Persona" if getattr(self, '_editing_persona_is_new', True) else f"Editing Persona: {self._editing_persona_name}" - imgui.text_colored(C_IN, header); imgui.separator() + # Bottom buttons reserved space + imgui.begin_child("persona_editor_content", imgui.ImVec2(0, avail.y - 45), False) + + header_text = "New Persona" if getattr(self, '_editing_persona_is_new', True) else f"Editing Persona: {self._editing_persona_name}" + imgui.text_colored(C_IN, header_text); imgui.separator() - # Metadata if imgui.begin_table("p_meta", 2): imgui.table_setup_column("L", imgui.TableColumnFlags_.width_fixed, 60); imgui.table_setup_column("F", imgui.TableColumnFlags_.width_stretch) imgui.table_next_row(); imgui.table_next_column(); imgui.text("Name:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, self._editing_persona_name = imgui.input_text("##pname", self._editing_persona_name, 128) @@ -1300,52 +1340,60 @@ class App: if imgui.radio_button("Project##pscope", getattr(self, '_editing_persona_scope', 'project') == "project"): self._editing_persona_scope = "project" imgui.end_table() - # Resizable Vertical Split for Models vs Prompt - total_h = imgui.get_content_region_avail().y - 120 # Account for headers and middle tools - h1 = total_h * self._persona_split_v - h2 = total_h - h1 - 8 # Splitter height + # Vertical Distribution Logic + header_h = 30 + rem_y = imgui.get_content_region_avail().y - 100 # Adjust for tables/headers - imgui.dummy(imgui.ImVec2(0, 4)); imgui.separator(); imgui.text("Preferred Models:") - imgui.begin_child("pref_models_scroll", imgui.ImVec2(0, h1), True) - to_remove = [] - providers = self.controller.PROVIDERS - if not hasattr(self, '_persona_pref_models_expanded'): self._persona_pref_models_expanded = {} - for i, entry in enumerate(self._editing_persona_preferred_models_list): - imgui.push_id(f"pref_model_{i}") - prov, mod, is_expanded = entry.get("provider", "Unknown"), entry.get("model", "Unknown"), self._persona_pref_models_expanded.get(i, False) - if imgui.button("-" if is_expanded else "+"): self._persona_pref_models_expanded[i] = not is_expanded - imgui.same_line(); imgui.text(f"{i+1}."); imgui.same_line(); imgui.text_colored(C_LBL, f"{prov}"); imgui.same_line(); imgui.text("-"); imgui.same_line(); imgui.text_colored(C_IN, f"{mod}") - if not is_expanded: - imgui.same_line(); summary = f" (T:{entry.get('temperature', 0.7):.1f}, M:{entry.get('max_output_tokens', 0)}, H:{entry.get('history_trunc_limit', 0)})" - imgui.text_colored(C_SUB, summary) - imgui.same_line(imgui.get_content_region_avail().x - 30); - if imgui.button("x"): to_remove.append(i) - if is_expanded: - imgui.indent(20) - if imgui.begin_table("model_settings", 2, imgui.TableFlags_.borders_inner_v): - imgui.table_setup_column("Label", imgui.TableColumnFlags_.width_fixed, 120); imgui.table_setup_column("Control", imgui.TableColumnFlags_.width_stretch) - imgui.table_next_row(); imgui.table_next_column(); imgui.text("Provider:"); imgui.table_next_column(); imgui.set_next_item_width(-1) - p_idx = providers.index(prov) + 1 if prov in providers else 0; ch_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers) - if ch_p: entry["provider"] = providers[p_idx-1] if p_idx > 0 else "" - imgui.table_next_row(); imgui.table_next_column(); imgui.text("Model:"); imgui.table_next_column(); imgui.set_next_item_width(-1) - m_list = self.controller.all_available_models.get(entry.get("provider", ""), []); m_idx = m_list.index(mod) + 1 if mod in m_list else 0 - ch_m, m_idx = imgui.combo("##model", m_idx, ["None"] + m_list) - if ch_m: entry["model"] = m_list[m_idx-1] if m_idx > 0 else "" - imgui.table_next_row(); imgui.table_next_column(); imgui.text("Temperature:"); imgui.table_next_column(); cw = imgui.get_content_region_avail().x - imgui.set_next_item_width(cw * 0.7); _, entry["temperature"] = imgui.slider_float("##ts", entry.get("temperature", 0.7), 0.0, 2.0, "%.1f") - imgui.same_line(); imgui.set_next_item_width(-1); _, entry["temperature"] = imgui.input_float("##ti", entry.get("temperature", 0.7), 0.1, 0.1, "%.1f") - imgui.table_next_row(); imgui.table_next_column(); imgui.text("Max Tokens:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, entry["max_output_tokens"] = imgui.input_int("##maxt", entry.get("max_output_tokens", 4096)) - imgui.table_next_row(); imgui.table_next_column(); imgui.text("History Limit:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, entry["history_trunc_limit"] = imgui.input_int("##hist", entry.get("history_trunc_limit", 900000)) - imgui.end_table() - imgui.unindent(20) - imgui.pop_id() - for i in reversed(to_remove): self._editing_persona_preferred_models_list.pop(i) - imgui.end_child() + if self._persona_models_open and self._persona_prompt_open: + h1 = rem_y * self._persona_split_v + h2 = rem_y - h1 - 10 + elif self._persona_models_open: h1, h2 = rem_y, 0 + elif self._persona_prompt_open: h1, h2 = 0, rem_y + else: h1, h2 = 0, 0 + + imgui.dummy(imgui.ImVec2(0, 4)) + opened_models = imgui.collapsing_header("Preferred Models", imgui.TreeNodeFlags_.default_open) + if opened_models != self._persona_models_open: self._persona_models_open = opened_models - # Custom Splitter - imgui.button("###persona_splitter", imgui.ImVec2(-1, 4)) - if imgui.is_item_active(): - self._persona_split_v = max(0.1, min(0.9, self._persona_split_v + imgui.get_io().mouse_delta.y / total_h)) + if self._persona_models_open: + imgui.begin_child("pref_models_scroll", imgui.ImVec2(0, h1), True) + to_remove = [] + providers = self.controller.PROVIDERS + if not hasattr(self, '_persona_pref_models_expanded'): self._persona_pref_models_expanded = {} + for i, entry in enumerate(self._editing_persona_preferred_models_list): + imgui.push_id(f"pref_model_{i}") + prov, mod, is_expanded = entry.get("provider", "Unknown"), entry.get("model", "Unknown"), self._persona_pref_models_expanded.get(i, False) + if imgui.button("-" if is_expanded else "+"): self._persona_pref_models_expanded[i] = not is_expanded + imgui.same_line(); imgui.text(f"{i+1}."); imgui.same_line(); imgui.text_colored(C_LBL, f"{prov}"); imgui.same_line(); imgui.text("-"); imgui.same_line(); imgui.text_colored(C_IN, f"{mod}") + if not is_expanded: + imgui.same_line(); summary = f" (T:{entry.get('temperature', 0.7):.1f}, M:{entry.get('max_output_tokens', 0)}, H:{entry.get('history_trunc_limit', 0)})" + imgui.text_colored(C_SUB, summary) + imgui.same_line(imgui.get_content_region_avail().x - 30); + if imgui.button("x"): to_remove.append(i) + if is_expanded: + imgui.indent(20) + if imgui.begin_table("model_settings", 2, imgui.TableFlags_.borders_inner_v): + imgui.table_setup_column("Label", imgui.TableColumnFlags_.width_fixed, 120); imgui.table_setup_column("Control", imgui.TableColumnFlags_.width_stretch) + imgui.table_next_row(); imgui.table_next_column(); imgui.text("Provider:"); imgui.table_next_column(); imgui.set_next_item_width(-1) + p_idx = providers.index(prov) + 1 if prov in providers else 0; ch_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers) + if ch_p: entry["provider"] = providers[p_idx-1] if p_idx > 0 else "" + imgui.table_next_row(); imgui.table_next_column(); imgui.text("Model:"); imgui.table_next_column(); imgui.set_next_item_width(-1) + m_list = self.controller.all_available_models.get(entry.get("provider", ""), []); m_idx = m_list.index(mod) + 1 if mod in m_list else 0 + ch_m, m_idx = imgui.combo("##model", m_idx, ["None"] + m_list) + if ch_m: entry["model"] = m_list[m_idx-1] if m_idx > 0 else "" + imgui.table_next_row(); imgui.table_next_column(); imgui.text("Temperature:"); imgui.table_next_column(); cw = imgui.get_content_region_avail().x + imgui.set_next_item_width(cw * 0.7); _, entry["temperature"] = imgui.slider_float("##ts", entry.get("temperature", 0.7), 0.0, 2.0, "%.1f") + imgui.same_line(); imgui.set_next_item_width(-1); _, entry["temperature"] = imgui.input_float("##ti", entry.get("temperature", 0.7), 0.1, 0.1, "%.1f") + imgui.table_next_row(); imgui.table_next_column(); imgui.text("Max Tokens:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, entry["max_output_tokens"] = imgui.input_int("##maxt", entry.get("max_output_tokens", 4096)) + imgui.table_next_row(); imgui.table_next_column(); imgui.text("History Limit:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, entry["history_trunc_limit"] = imgui.input_int("##hist", entry.get("history_trunc_limit", 900000)) + imgui.end_table() + imgui.unindent(20) + imgui.pop_id() + for i in reversed(to_remove): self._editing_persona_preferred_models_list.pop(i) + imgui.end_child() + if self._persona_prompt_open: + imgui.button("###persona_splitter", imgui.ImVec2(-1, 4)) + if imgui.is_item_active(): self._persona_split_v = max(0.1, min(0.9, self._persona_split_v + imgui.get_io().mouse_delta.y / rem_y)) imgui.dummy(imgui.ImVec2(0, 2)) if imgui.button("Add Preferred Model", imgui.ImVec2(-1, 0)): self._editing_persona_preferred_models_list.append({"provider": self.current_provider, "model": self.current_model, "temperature": 0.7, "max_output_tokens": 4096, "history_trunc_limit": 900000}) @@ -1362,23 +1410,28 @@ class App: imgui.end_table() if imgui.button("Manage Tools & Biases", imgui.ImVec2(-1, 0)): self.show_tool_preset_manager_window = True - imgui.dummy(imgui.ImVec2(0, 4)); imgui.separator(); imgui.text("System Prompt:") - imgui.begin_child("p_prompt_header", imgui.ImVec2(0, 30), False) - imgui.text("Template:"); imgui.same_line(); p_pre = ["Select..."] + sorted(self.controller.presets.keys()) - if not hasattr(self, "_load_preset_idx"): self._load_preset_idx = 0 - imgui.set_next_item_width(200); _, self._load_preset_idx = imgui.combo("##load_p", self._load_preset_idx, p_pre) - imgui.same_line(); - if imgui.button("Apply"): - if self._load_preset_idx > 0: self._editing_persona_system_prompt = self.controller.presets[p_pre[self._load_preset_idx]].system_prompt - imgui.same_line(); - if imgui.button("Manage"): self.show_preset_manager_window = True - imgui.end_child() - _, self._editing_persona_system_prompt = imgui.input_text_multiline("##pprompt", self._editing_persona_system_prompt, imgui.ImVec2(-1, h2)) + + imgui.dummy(imgui.ImVec2(0, 4)); imgui.separator() + opened_prompt = imgui.collapsing_header("System Prompt", imgui.TreeNodeFlags_.default_open) + if opened_prompt != self._persona_prompt_open: self._persona_prompt_open = opened_prompt + + if self._persona_prompt_open: + imgui.begin_child("p_prompt_header", imgui.ImVec2(0, 30), False) + imgui.text("Template:"); imgui.same_line(); p_pre = ["Select..."] + sorted(self.controller.presets.keys()) + if not hasattr(self, "_load_preset_idx"): self._load_preset_idx = 0 + imgui.set_next_item_width(200); _, self._load_preset_idx = imgui.combo("##load_p", self._load_preset_idx, p_pre) + imgui.same_line(); + if imgui.button("Apply"): + if self._load_preset_idx > 0: self._editing_persona_system_prompt = self.controller.presets[p_pre[self._load_preset_idx]].system_prompt + imgui.same_line(); + if imgui.button("Manage"): self.show_preset_manager_window = True + imgui.end_child() + _, self._editing_persona_system_prompt = imgui.input_text_multiline("##pprompt", self._editing_persona_system_prompt, imgui.ImVec2(-1, h2)) imgui.end_child() - # Fixed Bottom Buttons + # --- Footer Buttons --- imgui.separator() - if imgui.button("Save Persona", imgui.ImVec2(150, 0)): + if imgui.button("Save", imgui.ImVec2(100, 0)): if self._editing_persona_name.strip(): try: import copy; persona = models.Persona(name=self._editing_persona_name.strip(), system_prompt=self._editing_persona_system_prompt, tool_preset=self._editing_persona_tool_preset_id or None, bias_profile=self._editing_persona_bias_profile_id or None, preferred_models=copy.deepcopy(self._editing_persona_preferred_models_list)) @@ -1394,6 +1447,10 @@ class App: imgui.same_line(); if imgui.button("Close", imgui.ImVec2(100, 0)): self.show_persona_editor_window = False imgui.end_table() + except Exception as e: + import traceback + traceback.print_exc() + imgui.text_colored(vec4(255, 0, 0), f"Error in Persona Editor: {e}") finally: if not is_embedded: imgui.end() def _render_projects_panel(self) -> None: