2 Commits

Author SHA1 Message Date
ed 44fd370167 more refinement 2026-03-11 21:11:13 -04:00
ed b5007ce96f gui_2.py persona/prompt/tool preset menu refinement 2026-03-11 21:02:12 -04:00
+379 -512
View File
@@ -928,79 +928,147 @@ class App:
def _render_preset_manager_content(self, is_embedded: bool = False) -> None: def _render_preset_manager_content(self, is_embedded: bool = False) -> None:
avail = imgui.get_content_region_avail() avail = imgui.get_content_region_avail()
imgui.begin_child("preset_list_area", imgui.ImVec2(avail.x * 0.25, avail.y), True) if not hasattr(self, "_prompt_md_preview"): self._prompt_md_preview = False
try:
preset_names = sorted(self.controller.presets.keys())
if imgui.button("New Preset", imgui.ImVec2(-1, 0)):
self._editing_preset_name = ""
self._editing_preset_content = ""
self._editing_preset_scope = "project"
self._editing_preset_is_new = True
imgui.separator()
for name in preset_names:
p = self.controller.presets[name]
is_sel = (name == self._editing_preset_name)
if imgui.selectable(name, is_sel)[0]:
self._editing_preset_name = name
self._editing_preset_content = p.system_prompt
self._editing_preset_is_new = False
finally:
imgui.end_child()
imgui.same_line()
imgui.begin_child("preset_edit_area", imgui.ImVec2(0, avail.y), False)
try:
p_name = self._editing_preset_name or "(New Preset)"
imgui.text_colored(C_IN, f"Editing Preset: {p_name}")
imgui.separator()
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Name:")
imgui.set_next_item_width(-1)
_, self._editing_preset_name = imgui.input_text("##edit_name", self._editing_preset_name)
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Scope:")
if imgui.radio_button("Global", self._editing_preset_scope == "global"):
self._editing_preset_scope = "global"
imgui.same_line()
if imgui.radio_button("Project", self._editing_preset_scope == "project"):
self._editing_preset_scope = "project"
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Content:")
_, self._editing_preset_content = imgui.input_text_multiline("##edit_content", self._editing_preset_content, imgui.ImVec2(-1, -40))
imgui.dummy(imgui.ImVec2(0, 8)) try:
if imgui.button("Save", imgui.ImVec2(120, 0)): if imgui.begin_table("prompt_main_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v):
if self._editing_preset_name.strip(): imgui.table_setup_column("List", imgui.TableColumnFlags_.width_fixed, 200)
self.controller._cb_save_preset( imgui.table_setup_column("Editor", imgui.TableColumnFlags_.width_stretch)
self._editing_preset_name.strip(), imgui.table_next_row()
self._editing_preset_content,
self._editing_preset_scope # Left Column: Presets
) imgui.table_next_column()
self.ai_status = f"Preset '{self._editing_preset_name.strip()}' saved to {self._editing_preset_scope}" imgui.begin_child("prompt_list_pane", imgui.ImVec2(0, 0), False)
imgui.set_item_tooltip("Save the current preset settings") if imgui.button("New Preset", imgui.ImVec2(-1, 0)):
imgui.same_line() self._editing_preset_name = ""
if imgui.button("Delete", imgui.ImVec2(120, 0)): self._editing_preset_system_prompt = ""
if self._editing_preset_name.strip(): self._editing_preset_temperature = 0.7
try: self._editing_preset_top_p = 1.0
self.controller._cb_delete_preset(self._editing_preset_name.strip(), self._editing_preset_scope) self._editing_preset_max_output_tokens = 4096
self.ai_status = f"Preset '{self._editing_preset_name}' deleted from {self._editing_preset_scope}" self._editing_preset_scope = "project"
self._editing_preset_name = "" self._selected_preset_idx = -1
self._editing_preset_content = "" imgui.separator()
except Exception as e: preset_names = sorted(self.controller.presets.keys())
self.ai_status = f"Error deleting: {e}" for i, name in enumerate(preset_names):
imgui.set_item_tooltip("Delete the selected preset") if imgui.selectable(name, self._selected_preset_idx == i)[0]:
if not is_embedded: self._selected_preset_idx = i
self._editing_preset_name = name
p = self.controller.presets[name]
self._editing_preset_system_prompt = p.system_prompt
self._editing_preset_temperature = p.temperature
self._editing_preset_top_p = p.top_p
self._editing_preset_max_output_tokens = p.max_output_tokens
self._editing_preset_scope = self.controller.preset_manager.get_preset_scope(name)
imgui.end_child()
# Right Column: Editor
imgui.table_next_column()
avail_r = imgui.get_content_region_avail()
# Subtract space for bottom buttons (approx 45px)
imgui.begin_child("prompt_edit_pane", imgui.ImVec2(0, avail_r.y - 45), False)
p_disp = self._editing_preset_name or "(New Preset)"
imgui.text_colored(C_IN, f"Editing Preset: {p_disp}")
imgui.separator()
if imgui.begin_table("p_meta", 2):
imgui.table_setup_column("L", imgui.TableColumnFlags_.width_fixed, 80)
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_preset_name = imgui.input_text("##epn", self._editing_preset_name)
imgui.table_next_row()
imgui.table_next_column()
imgui.text("Scope:")
imgui.table_next_column()
if imgui.radio_button("Global", self._editing_preset_scope == "global"):
self._editing_preset_scope = "global"
imgui.same_line()
if imgui.radio_button("Project", self._editing_preset_scope == "project"):
self._editing_preset_scope = "project"
imgui.end_table()
imgui.dummy(imgui.ImVec2(0, 4))
imgui.separator()
imgui.text("Parameters:")
if imgui.begin_table("p_params", 2):
imgui.table_setup_column("L", imgui.TableColumnFlags_.width_fixed, 120)
imgui.table_setup_column("C", imgui.TableColumnFlags_.width_stretch)
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)
_, self._editing_preset_temperature = imgui.slider_float("##pts", self._editing_preset_temperature, 0.0, 2.0, "%.1f")
imgui.same_line()
imgui.set_next_item_width(-1)
_, self._editing_preset_temperature = imgui.input_float("##pti", self._editing_preset_temperature, 0.1, 0.1, "%.1f")
imgui.table_next_row()
imgui.table_next_column()
imgui.text("Top-P:")
imgui.table_next_column()
imgui.set_next_item_width(cw * 0.7)
_, self._editing_preset_top_p = imgui.slider_float("##ptp_s", self._editing_preset_top_p, 0.0, 1.0, "%.2f")
imgui.same_line()
imgui.set_next_item_width(-1)
_, self._editing_preset_top_p = imgui.input_float("##ptp_i", self._editing_preset_top_p, 0.05, 0.05, "%.2f")
imgui.table_next_row()
imgui.table_next_column()
imgui.text("Max Tokens:")
imgui.table_next_column()
imgui.set_next_item_width(-1)
_, self._editing_preset_max_output_tokens = imgui.input_int("##pmaxt", self._editing_preset_max_output_tokens)
imgui.end_table()
imgui.dummy(imgui.ImVec2(0, 4))
imgui.separator()
imgui.text("Prompt Content:")
imgui.same_line() imgui.same_line()
if imgui.button("Close", imgui.ImVec2(120, 0)): if imgui.button("MD Preview" if not self._prompt_md_preview else "Edit Mode"):
self.show_preset_manager_window = False self._prompt_md_preview = not self._prompt_md_preview
if self._prompt_md_preview:
imgui.begin_child("prompt_preview", imgui.ImVec2(-1, imgui.get_content_region_avail().y), True)
self.markdown_renderer.render(self._editing_preset_system_prompt)
imgui.end_child()
else:
_, self._editing_preset_system_prompt = imgui.input_text_multiline("##pcont", self._editing_preset_system_prompt, imgui.ImVec2(-1, imgui.get_content_region_avail().y))
imgui.end_child()
# Bottom Buttons
imgui.separator()
imgui.dummy(imgui.ImVec2(0, 4))
if imgui.button("Save Preset", imgui.ImVec2(150, 0)):
if self._editing_preset_name.strip():
p = models.Preset(name=self._editing_preset_name.strip(), system_prompt=self._editing_preset_system_prompt, temperature=self._editing_preset_temperature, top_p=self._editing_preset_top_p, max_output_tokens=self._editing_preset_max_output_tokens)
self.controller._cb_save_preset(p, self._editing_preset_scope)
self.ai_status = f"Saved: {p.name}"
imgui.same_line()
if imgui.button("Delete Preset", imgui.ImVec2(120, 0)):
if self._editing_preset_name:
self.controller._cb_delete_preset(self._editing_preset_name, self._editing_preset_scope)
self._editing_preset_name = ""
self._selected_preset_idx = -1
if not is_embedded:
imgui.same_line()
if imgui.button("Close", imgui.ImVec2(100, 0)):
self.show_preset_manager_window = False
imgui.end_table()
finally: finally:
imgui.end_child() pass
def _render_preset_manager_window(self, is_embedded: bool = False) -> None: def _render_preset_manager_window(self, is_embedded: bool = False) -> None:
if not self.show_preset_manager_window and not is_embedded: return if not self.show_preset_manager_window and not is_embedded: return
if not is_embedded: if not is_embedded:
imgui.set_next_window_size(imgui.ImVec2(800, 600), imgui.Cond_.first_use_ever) imgui.set_next_window_size(imgui.ImVec2(1000, 800), imgui.Cond_.first_use_ever)
opened, self.show_preset_manager_window = imgui.begin("Preset Manager", self.show_preset_manager_window) opened, self.show_preset_manager_window = imgui.begin("Prompt Presets Manager", self.show_preset_manager_window)
if not opened: if not opened:
imgui.end() imgui.end()
return return
@@ -1013,248 +1081,158 @@ class App:
def _render_tool_preset_manager_content(self, is_embedded: bool = False) -> None: def _render_tool_preset_manager_content(self, is_embedded: bool = False) -> None:
avail = imgui.get_content_region_avail() avail = imgui.get_content_region_avail()
# Left Column: Listbox if not hasattr(self, "_tool_split_v"): self._tool_split_v = 0.4
imgui.begin_child("tool_preset_list_area", imgui.ImVec2(avail.x * 0.25, avail.y), True)
try: try:
if imgui.button("New Tool Preset", imgui.ImVec2(-1, 0)): if imgui.begin_table("tp_main_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v):
self._editing_tool_preset_name = "" imgui.table_setup_column("List", imgui.TableColumnFlags_.width_fixed, 200)
self._editing_tool_preset_categories = {cat: {} for cat in models.DEFAULT_TOOL_CATEGORIES} imgui.table_setup_column("Editor", imgui.TableColumnFlags_.width_stretch)
self._editing_tool_preset_scope = "project" imgui.table_next_row()
self._selected_tool_preset_idx = -1
if imgui.is_item_hovered():
imgui.set_tooltip("Create a new tool preset configuration.")
imgui.separator() # Left Sidebar
preset_names = sorted(self.controller.tool_presets.keys()) imgui.table_next_column()
for i, name in enumerate(preset_names): imgui.begin_child("tp_list_pane", imgui.ImVec2(0, 0), False)
is_selected = (self._selected_tool_preset_idx == i) if imgui.button("New Tool Preset", imgui.ImVec2(-1, 0)):
if imgui.selectable(name, is_selected)[0]: self._editing_tool_preset_name = ""; self._editing_tool_preset_categories = {cat: {} for cat in models.DEFAULT_TOOL_CATEGORIES}
self._selected_tool_preset_idx = i self._editing_tool_preset_scope = "project"; self._selected_tool_preset_idx = -1
self._editing_tool_preset_name = name
preset = self.controller.tool_presets[name]
self._editing_tool_preset_categories = {cat: {} for cat in models.DEFAULT_TOOL_CATEGORIES}
for cat, tools in preset.categories.items():
self._editing_tool_preset_categories[cat] = copy.deepcopy(tools)
finally:
imgui.end_child()
imgui.same_line()
# Right Column: Edit Area
imgui.begin_child("tool_preset_edit_area", imgui.ImVec2(0, avail.y), False)
try:
p_name = self._editing_tool_preset_name or "(New Tool Preset)"
imgui.text_colored(C_IN, f"Editing Tool Preset: {p_name}")
imgui.separator()
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Name:")
imgui.set_next_item_width(-1)
_, self._editing_tool_preset_name = imgui.input_text("##edit_tp_name", self._editing_tool_preset_name)
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Scope:")
if imgui.radio_button("Global", self._editing_tool_preset_scope == "global"):
self._editing_tool_preset_scope = "global"
imgui.same_line()
if imgui.radio_button("Project", self._editing_tool_preset_scope == "project"):
self._editing_tool_preset_scope = "project"
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Categories & Tools:")
cat_options = ["All"] + sorted(list(models.DEFAULT_TOOL_CATEGORIES.keys()))
try:
f_idx = cat_options.index(self.ui_tool_filter_category)
except ValueError:
f_idx = 0
imgui.set_next_item_width(200)
ch_cat, next_f_idx = imgui.combo("Filter Category##tp", f_idx, cat_options)
if ch_cat:
self.ui_tool_filter_category = cat_options[next_f_idx]
imgui.begin_child("tp_categories_scroll", imgui.ImVec2(0, 300), True)
try:
for cat_name, default_tools in models.DEFAULT_TOOL_CATEGORIES.items():
if self.ui_tool_filter_category != "All" and self.ui_tool_filter_category != cat_name:
continue
if imgui.tree_node(cat_name):
if cat_name not in self._editing_tool_preset_categories:
self._editing_tool_preset_categories[cat_name] = []
current_cat_tools = self._editing_tool_preset_categories[cat_name] # List of Tool
for tool_name in default_tools:
# Find existing Tool object in list
tool = next((t for t in current_cat_tools if t.name == tool_name), None)
mode = "disabled" if tool is None else tool.approval
imgui.text(tool_name)
imgui.same_line(180)
if imgui.radio_button(f"Off##{cat_name}_{tool_name}", mode == "disabled"):
if tool: current_cat_tools.remove(tool)
imgui.same_line()
if imgui.radio_button(f"Auto##{cat_name}_{tool_name}", mode == "auto"):
if not tool:
tool = models.Tool(name=tool_name, approval="auto")
current_cat_tools.append(tool)
else:
tool.approval = "auto"
imgui.same_line()
if imgui.radio_button(f"Ask##{cat_name}_{tool_name}", mode == "ask"):
if not tool:
tool = models.Tool(name=tool_name, approval="ask")
current_cat_tools.append(tool)
else:
tool.approval = "ask"
if tool:
imgui.same_line(350)
imgui.set_next_item_width(100)
_, tool.weight = imgui.slider_int(f"Weight##{cat_name}_{tool_name}", tool.weight, 1, 5)
imgui.same_line()
pb_str = json.dumps(tool.parameter_bias)
imgui.set_next_item_width(150)
ch_pb, pb_new = imgui.input_text(f"Params##{cat_name}_{tool_name}", pb_str)
if ch_pb:
try: tool.parameter_bias = json.loads(pb_new)
except: pass
imgui.tree_pop()
finally:
imgui.end_child()
imgui.dummy(imgui.ImVec2(0, 8))
imgui.separator()
imgui.text_colored(C_SUB, "Bias Profiles")
imgui.begin_child("bias_profiles_area", imgui.ImVec2(0, 300), True)
try:
avail_bias = imgui.get_content_region_avail()
imgui.begin_child("bias_list", imgui.ImVec2(avail_bias.x * 0.3, avail_bias.y), False)
if imgui.button("New Profile", imgui.ImVec2(-1, 0)):
self._editing_bias_profile_name = ""
self._editing_bias_profile_tool_weights = {}
self._editing_bias_profile_category_multipliers = {}
self._selected_bias_profile_idx = -1
imgui.separator() imgui.separator()
bnames = sorted(self.bias_profiles.keys()) preset_names = sorted(self.controller.tool_presets.keys())
for i, bname in enumerate(bnames): for i, name in enumerate(preset_names):
is_sel = (self._selected_bias_profile_idx == i) if imgui.selectable(name, self._selected_tool_preset_idx == i)[0]:
if imgui.selectable(bname, is_sel)[0]: self._selected_tool_preset_idx = i; self._editing_tool_preset_name = name
self._selected_bias_profile_idx = i preset = self.controller.tool_presets[name]
self._editing_bias_profile_name = bname self._editing_tool_preset_categories = {cat: copy.deepcopy(tools) for cat, tools in preset.categories.items()}
profile = self.bias_profiles[bname]
self._editing_bias_profile_tool_weights = copy.deepcopy(profile.tool_weights)
self._editing_bias_profile_category_multipliers = copy.deepcopy(profile.category_multipliers)
imgui.end_child() imgui.end_child()
imgui.same_line()
imgui.begin_child("bias_edit", imgui.ImVec2(0, avail_bias.y), False)
imgui.text("Name:")
imgui.set_next_item_width(-1)
_, self._editing_bias_profile_name = imgui.input_text("##b_name", self._editing_bias_profile_name)
imgui.text_colored(C_KEY, "Tool Weights:") # Right Editor
to_remove_tw = [] imgui.table_next_column()
for tw_name, tw_val in list(self._editing_bias_profile_tool_weights.items()): avail_r = imgui.get_content_region_avail()
imgui.text(f" {tw_name}:") # Leave space for bottom buttons
imgui.same_line(150) imgui.begin_child("tp_editor_content", imgui.ImVec2(0, avail_r.y - 45), False)
imgui.set_next_item_width(100)
changed, new_val = imgui.slider_int(f"##tw_{tw_name}", tw_val, 1, 10)
if changed: self._editing_bias_profile_tool_weights[tw_name] = new_val
imgui.same_line()
if imgui.button(f"x##rem_tw_{tw_name}"):
to_remove_tw.append(tw_name)
for r in to_remove_tw: del self._editing_bias_profile_tool_weights[r]
# Add Tool Override p_name = self._editing_tool_preset_name or "(New Tool Preset)"
imgui.set_next_item_width(150) imgui.text_colored(C_IN, f"Editing Tool Preset: {p_name}"); imgui.separator()
if imgui.begin_combo("##add_tw_combo", self._new_bias_tool_name):
for tn in models.AGENT_TOOL_NAMES: if imgui.begin_table("tp_meta", 2):
if tn not in self._editing_bias_profile_tool_weights: imgui.table_setup_column("L", imgui.TableColumnFlags_.width_fixed, 80); imgui.table_setup_column("F", imgui.TableColumnFlags_.width_stretch)
if imgui.selectable(tn, tn == self._new_bias_tool_name)[0]: imgui.table_next_row(); imgui.table_next_column(); imgui.text("Name:"); imgui.table_next_column(); imgui.set_next_item_width(-1); _, self._editing_tool_preset_name = imgui.input_text("##etpn", self._editing_tool_preset_name)
self._new_bias_tool_name = tn imgui.table_next_row(); imgui.table_next_column(); imgui.text("Scope:"); imgui.table_next_column()
imgui.end_combo() if imgui.radio_button("Global", self._editing_tool_preset_scope == "global"): self._editing_tool_preset_scope = "global"
imgui.same_line() imgui.same_line();
if imgui.button("Add Tool Override"): if imgui.radio_button("Project", self._editing_tool_preset_scope == "project"): self._editing_tool_preset_scope = "project"
self._editing_bias_profile_tool_weights[self._new_bias_tool_name] = 5 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
imgui.dummy(imgui.ImVec2(0, 4)) imgui.dummy(imgui.ImVec2(0, 4))
imgui.text_colored(C_KEY, "Category Multipliers:") if imgui.collapsing_header("Categories & Tools", imgui.TreeNodeFlags_.default_open):
to_remove_cm = [] imgui.text("Filter:"); imgui.same_line()
for cm_name, cm_val in list(self._editing_bias_profile_category_multipliers.items()): cat_opts = ["All"] + sorted(list(models.DEFAULT_TOOL_CATEGORIES.keys()))
imgui.text(f" {cm_name}:") f_idx = cat_opts.index(self.ui_tool_filter_category) if self.ui_tool_filter_category in cat_opts else 0
imgui.same_line(150) imgui.set_next_item_width(200); ch_cat, next_f_idx = imgui.combo("##tp_filter", f_idx, cat_opts)
imgui.set_next_item_width(100) if ch_cat: self.ui_tool_filter_category = cat_opts[next_f_idx]
changed, new_val = imgui.slider_float(f"##cm_{cm_name}", cm_val, 0.1, 5.0, "%.1fx")
if changed: self._editing_bias_profile_category_multipliers[cm_name] = new_val
imgui.same_line()
if imgui.button(f"x##rem_cm_{cm_name}"):
to_remove_cm.append(cm_name)
for r in to_remove_cm: del self._editing_bias_profile_category_multipliers[r]
# Add Category Override imgui.begin_child("tp_scroll", imgui.ImVec2(0, h1), True)
imgui.set_next_item_width(150) for cat_name, default_tools in models.DEFAULT_TOOL_CATEGORIES.items():
cat_names = sorted(list(models.DEFAULT_TOOL_CATEGORIES.keys())) if self.ui_tool_filter_category != "All" and self.ui_tool_filter_category != cat_name: continue
if imgui.begin_combo("##add_cm_combo", self._new_bias_category_name): if imgui.tree_node(cat_name):
for cn in cat_names: if cat_name not in self._editing_tool_preset_categories: self._editing_tool_preset_categories[cat_name] = []
if cn not in self._editing_bias_profile_category_multipliers: curr_cat_tools = self._editing_tool_preset_categories[cat_name]
if imgui.selectable(cn, cn == self._new_bias_category_name)[0]: if imgui.begin_table(f"tt_{cat_name}", 2, imgui.TableFlags_.borders_inner_v):
self._new_bias_category_name = cn imgui.table_setup_column("Tool", imgui.TableColumnFlags_.width_fixed, 180); imgui.table_setup_column("Ctrls", imgui.TableColumnFlags_.width_stretch)
imgui.end_combo() for tool_name in default_tools:
imgui.same_line() tool = next((t for t in curr_cat_tools if t.name == tool_name), None)
if imgui.button("Add Category Override"): mode = "disabled" if tool is None else tool.approval
self._editing_bias_profile_category_multipliers[self._new_bias_category_name] = 1.0 imgui.table_next_row(); imgui.table_next_column(); imgui.text(tool_name); imgui.table_next_column()
if imgui.radio_button(f"Off##{cat_name}_{tool_name}", mode == "disabled"):
if tool: curr_cat_tools.remove(tool)
imgui.same_line();
if imgui.radio_button(f"Auto##{cat_name}_{tool_name}", mode == "auto"):
if not tool: tool = models.Tool(name=tool_name, approval="auto"); current_cat_tools.append(tool)
else: tool.approval = "auto"
imgui.same_line();
if imgui.radio_button(f"Ask##{cat_name}_{tool_name}", mode == "ask"):
if not tool: tool = models.Tool(name=tool_name, approval="ask"); current_cat_tools.append(tool)
else: tool.approval = "ask"
if tool:
imgui.same_line(); imgui.text(" W:"); imgui.same_line(); imgui.set_next_item_width(60); _, tool.weight = imgui.slider_int(f"##w_{cat_name}_{tool_name}", tool.weight, 1, 5)
imgui.same_line(); imgui.text(" P:"); imgui.same_line(); imgui.set_next_item_width(-1); pb_str = json.dumps(tool.parameter_bias)
ch_pb, pb_new = imgui.input_text(f"##pb_{cat_name}_{tool_name}", pb_str)
if ch_pb:
try: tool.parameter_bias = json.loads(pb_new)
except: pass
imgui.end_table(); imgui.tree_pop()
imgui.end_child()
imgui.dummy(imgui.ImVec2(0, 8)) # Vertical Splitter
if imgui.button("Save Profile"): imgui.button("###tool_splitter", imgui.ImVec2(-1, 4))
try: if imgui.is_item_active():
prof = models.BiasProfile( self._tool_split_v = max(0.1, min(0.9, self._tool_split_v + imgui.get_io().mouse_delta.y / total_h))
name=self._editing_bias_profile_name,
tool_weights=self._editing_bias_profile_tool_weights, imgui.dummy(imgui.ImVec2(0, 4))
category_multipliers=self._editing_bias_profile_category_multipliers if imgui.collapsing_header("Bias Profiles", imgui.TreeNodeFlags_.default_open):
) imgui.begin_child("bias_area", imgui.ImVec2(0, h2), True)
self.controller._cb_save_bias_profile(prof, self._editing_tool_preset_scope) if imgui.begin_table("bias_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v):
self.ai_status = f"Bias profile '{prof.name}' saved" imgui.table_setup_column("BList", imgui.TableColumnFlags_.width_fixed, 150); imgui.table_setup_column("BEdit", imgui.TableColumnFlags_.width_stretch)
except Exception as e: imgui.table_next_row(); imgui.table_next_column()
self.ai_status = f"Error: {e}" imgui.begin_child("blist_pane", imgui.ImVec2(0, 0), False)
imgui.same_line() if imgui.button("New Profile", imgui.ImVec2(-1, 0)):
if imgui.button("Delete Profile"): self._editing_bias_profile_name = ""; self._editing_bias_profile_tool_weights = {}
self.controller._cb_delete_bias_profile(self._editing_bias_profile_name, self._editing_tool_preset_scope) self._editing_bias_profile_category_multipliers = {}; self._selected_bias_profile_idx = -1
self.ai_status = f"Bias profile deleted" imgui.separator(); bnames = sorted(self.bias_profiles.keys())
imgui.end_child() for i, bname in enumerate(bnames):
finally: if imgui.selectable(bname, self._selected_bias_profile_idx == i)[0]:
self._selected_bias_profile_idx = i; self._editing_bias_profile_name = bname; prof = self.bias_profiles[bname]
self._editing_bias_profile_tool_weights = copy.deepcopy(prof.tool_weights); self._editing_bias_profile_category_multipliers = copy.deepcopy(prof.category_multipliers)
imgui.end_child()
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)
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)
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)
ch_w, n_w = imgui.slider_int(f"##bw_{tn}", curr_w, 1, 10);
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)
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)
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)
self.controller._cb_save_bias_profile(p, self._editing_tool_preset_scope); self.ai_status = f"Saved: {p.name}"
except Exception as e: self.ai_status = f"Error: {e}"
imgui.end_child(); imgui.end_table()
imgui.end_child()
imgui.end_child() imgui.end_child()
imgui.dummy(imgui.ImVec2(0, 8)) # Fixed Bottom Buttons
if imgui.button("Save", imgui.ImVec2(100, 0)): imgui.separator()
if self._editing_tool_preset_name.strip(): if imgui.button("Save Tool Preset", imgui.ImVec2(150, 0)):
self.controller._cb_save_tool_preset( 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}"
self._editing_tool_preset_name.strip(), imgui.same_line();
self._editing_tool_preset_categories, if imgui.button("Delete Preset", imgui.ImVec2(120, 0)):
self._editing_tool_preset_scope 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();
self.ai_status = f"Tool preset '{self._editing_tool_preset_name}' saved" if not is_embedded:
if imgui.is_item_hovered(): if imgui.button("Close", imgui.ImVec2(100, 0)): self.show_tool_preset_manager_window = False
imgui.set_tooltip("Save the current tool preset configuration.") imgui.end_table()
imgui.same_line()
if imgui.button("Delete", imgui.ImVec2(100, 0)):
if self._editing_tool_preset_name.strip():
self.controller._cb_delete_tool_preset(
self._editing_tool_preset_name.strip(),
self._editing_tool_preset_scope
)
self.ai_status = f"Tool preset '{self._editing_tool_preset_name}' deleted"
self._editing_tool_preset_name = ""
self._editing_tool_preset_categories = {}
self._selected_tool_preset_idx = -1
if imgui.is_item_hovered():
imgui.set_tooltip("Delete this tool preset permanently.")
if not is_embedded:
imgui.same_line()
if imgui.button("Close", imgui.ImVec2(100, 0)):
self.show_tool_preset_manager_window = False
finally: finally:
imgui.end_child() pass
def _render_tool_preset_manager_window(self, is_embedded: bool = False) -> None: def _render_tool_preset_manager_window(self, is_embedded: bool = False) -> None:
if not self.show_tool_preset_manager_window and not is_embedded: return if not self.show_tool_preset_manager_window and not is_embedded: return
@@ -1273,262 +1251,151 @@ class App:
imgui.end() imgui.end()
def _render_persona_editor_window(self, is_embedded: bool = False) -> None: def _render_persona_editor_window(self, is_embedded: bool = False) -> None:
if not self.show_persona_editor_window and not is_embedded: return if not self.show_persona_editor_window and not is_embedded: return
if not is_embedded: if not is_embedded:
imgui.set_next_window_size(imgui.ImVec2(1000, 800), imgui.Cond_.first_use_ever) imgui.set_next_window_size(imgui.ImVec2(1000, 800), imgui.Cond_.first_use_ever)
opened, self.show_persona_editor_window = imgui.begin("Persona Editor", self.show_persona_editor_window) opened, self.show_persona_editor_window = imgui.begin("Persona Editor", self.show_persona_editor_window)
if not opened: if not opened:
imgui.end() imgui.end(); return
return
if not hasattr(self, "_persona_split_v"): self._persona_split_v = 0.4
try: try:
avail = imgui.get_content_region_avail() if imgui.begin_table("persona_main_split", 2, imgui.TableFlags_.resizable | imgui.TableFlags_.borders_inner_v):
# Left Pane: List of Personas imgui.table_setup_column("List", imgui.TableColumnFlags_.width_fixed, 200)
imgui.begin_child("persona_list_area", imgui.ImVec2(avail.x * 0.25, avail.y), True) imgui.table_setup_column("Editor", imgui.TableColumnFlags_.width_stretch)
try: imgui.table_next_row()
# 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)): if imgui.button("New Persona", imgui.ImVec2(-1, 0)):
self._editing_persona_name = "" self._editing_persona_name = ""; self._editing_persona_system_prompt = ""
self._editing_persona_system_prompt = "" self._editing_persona_tool_preset_id = ""; self._editing_persona_bias_profile_id = ""
self._editing_persona_tool_preset_id = "" self._editing_persona_preferred_models_list = [{"provider": self.current_provider, "model": self.current_model, "temperature": 0.7, "max_output_tokens": 4096, "history_trunc_limit": 900000}]
self._editing_persona_bias_profile_id = "" self._editing_persona_scope = "project"; self._editing_persona_is_new = True
self._editing_persona_preferred_models_list = [{
"provider": self.current_provider,
"model": self.current_model,
"temperature": 0.7,
"max_output_tokens": 4096,
"history_trunc_limit": 900000
}]
self._editing_persona_scope = "project"
self._editing_persona_is_new = True
imgui.separator() imgui.separator()
personas = getattr(self.controller, 'personas', {}) personas = getattr(self.controller, 'personas', {})
for name in sorted(personas.keys()): for name in sorted(personas.keys()):
is_sel = (name == self._editing_persona_name and not getattr(self, '_editing_persona_is_new', False)) if imgui.selectable(name, name == self._editing_persona_name and not getattr(self, '_editing_persona_is_new', False))[0]:
if imgui.selectable(name, is_sel)[0]: p = personas[name]; self._editing_persona_name = p.name; self._editing_persona_system_prompt = p.system_prompt or ""
p = personas[name] self._editing_persona_tool_preset_id = p.tool_preset or ""; self._editing_persona_bias_profile_id = p.bias_profile or ""
self._editing_persona_name = p.name import copy; self._editing_persona_preferred_models_list = copy.deepcopy(p.preferred_models) if p.preferred_models else []
self._editing_persona_system_prompt = p.system_prompt or "" self._editing_persona_scope = self.controller.persona_manager.get_persona_scope(p.name); self._editing_persona_is_new = False
self._editing_persona_tool_preset_id = p.tool_preset or ""
self._editing_persona_bias_profile_id = p.bias_profile or ""
import copy
self._editing_persona_preferred_models_list = copy.deepcopy(p.preferred_models) if p.preferred_models else []
self._editing_persona_scope = self.controller.persona_manager.get_persona_scope(p.name)
self._editing_persona_is_new = False
finally:
imgui.end_child() imgui.end_child()
imgui.same_line() # Right Editor
imgui.table_next_column()
# Right Pane: Editor avail = imgui.get_content_region_avail()
imgui.begin_child("persona_edit_area", imgui.ImVec2(0, avail.y), False) # Ensure buttons stay at the absolute bottom
try: 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}" 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.text_colored(C_IN, header); imgui.separator()
imgui.separator()
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Name:") # Metadata
imgui.set_next_item_width(-1) if imgui.begin_table("p_meta", 2):
_, self._editing_persona_name = imgui.input_text("##pname", self._editing_persona_name, 128) imgui.table_setup_column("L", imgui.TableColumnFlags_.width_fixed, 60); imgui.table_setup_column("F", imgui.TableColumnFlags_.width_stretch)
imgui.dummy(imgui.ImVec2(0, 8)) 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)
imgui.table_next_row(); imgui.table_next_column(); imgui.text("Scope:"); imgui.table_next_column()
if imgui.radio_button("Global##pscope", getattr(self, '_editing_persona_scope', 'project') == "global"): self._editing_persona_scope = "global"
imgui.same_line();
if imgui.radio_button("Project##pscope", getattr(self, '_editing_persona_scope', 'project') == "project"): self._editing_persona_scope = "project"
imgui.end_table()
imgui.text("Scope:") # Resizable Vertical Split for Models vs Prompt
if imgui.radio_button("Global##pscope", getattr(self, '_editing_persona_scope', 'project') == "global"): total_h = imgui.get_content_region_avail().y - 120 # Account for headers and middle tools
self._editing_persona_scope = "global" h1 = total_h * self._persona_split_v
imgui.same_line() h2 = total_h - h1 - 8 # Splitter height
if imgui.radio_button("Project##pscope", getattr(self, '_editing_persona_scope', 'project') == "project"):
self._editing_persona_scope = "project"
imgui.dummy(imgui.ImVec2(0, 8))
imgui.separator() imgui.dummy(imgui.ImVec2(0, 4)); imgui.separator(); imgui.text("Preferred Models:")
imgui.dummy(imgui.ImVec2(0, 8)) imgui.begin_child("pref_models_scroll", imgui.ImVec2(0, h1), True)
imgui.text("Preferred Models:")
providers = self.controller.PROVIDERS
if not hasattr(self, '_persona_pref_models_expanded'):
self._persona_pref_models_expanded = {}
imgui.begin_child("pref_models_list", imgui.ImVec2(0, 200), True)
to_remove = [] to_remove = []
avail_edit = imgui.get_content_region_avail() 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): for i, entry in enumerate(self._editing_persona_preferred_models_list):
imgui.push_id(f"pref_model_{i}") 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)
prov = entry.get("provider", "Unknown") if imgui.button("-" if is_expanded else "+"): self._persona_pref_models_expanded[i] = not is_expanded
mod = entry.get("model", "Unknown") 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}")
is_expanded = self._persona_pref_models_expanded.get(i, False) 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)})"
if imgui.button("-" if is_expanded else "+"): imgui.text_colored(C_SUB, summary)
self._persona_pref_models_expanded[i] = not is_expanded imgui.same_line(imgui.get_content_region_avail().x - 30);
imgui.same_line() if imgui.button("x"): to_remove.append(i)
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}")
imgui.same_line(imgui.get_content_region_avail().x - 30)
if imgui.button("x"):
to_remove.append(i)
if is_expanded: if is_expanded:
imgui.indent(20) imgui.indent(20)
if imgui.begin_table("model_settings", 2, imgui.TableFlags_.borders_inner_v):
imgui.text("Provider:") imgui.table_setup_column("Label", imgui.TableColumnFlags_.width_fixed, 120); imgui.table_setup_column("Control", imgui.TableColumnFlags_.width_stretch)
imgui.same_line() imgui.table_next_row(); imgui.table_next_column(); imgui.text("Provider:"); imgui.table_next_column(); imgui.set_next_item_width(-1)
imgui.set_next_item_width(150) p_idx = providers.index(prov) + 1 if prov in providers else 0; ch_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers)
p_idx = providers.index(prov) + 1 if prov in providers else 0 if ch_p: entry["provider"] = providers[p_idx-1] if p_idx > 0 else ""
changed_p, p_idx = imgui.combo("##prov", p_idx, ["None"] + providers) imgui.table_next_row(); imgui.table_next_column(); imgui.text("Model:"); imgui.table_next_column(); imgui.set_next_item_width(-1)
if changed_p: 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
entry["provider"] = providers[p_idx-1] if p_idx > 0 else "" 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.same_line() imgui.table_next_row(); imgui.table_next_column(); imgui.text("Temperature:"); imgui.table_next_column(); cw = imgui.get_content_region_avail().x
imgui.text("Model:") 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.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.set_next_item_width(250) 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))
curr_prov = entry.get("provider", "") 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))
m_list = self.controller.all_available_models.get(curr_prov, []) imgui.end_table()
m_idx = m_list.index(mod) + 1 if mod in m_list else 0
changed_m, m_idx = imgui.combo("##model", m_idx, ["None"] + m_list)
if changed_m:
entry["model"] = m_list[m_idx-1] if m_idx > 0 else ""
imgui.text("Temperature:")
imgui.same_line()
imgui.set_next_item_width(avail_edit.x * 0.3)
_, entry["temperature"] = imgui.slider_float("##temp_slider", entry.get("temperature", 0.7), 0.0, 2.0, "%.1f")
imgui.same_line()
imgui.set_next_item_width(80)
_, entry["temperature"] = imgui.input_float("##temp_input", entry.get("temperature", 0.7), 0.1, 0.1, "%.1f")
imgui.same_line()
imgui.text("Max Output Tokens:")
imgui.same_line()
imgui.set_next_item_width(100)
_, entry["max_output_tokens"] = imgui.input_int("##maxt", entry.get("max_output_tokens", 4096))
imgui.text("History Truncation Limit:")
imgui.same_line()
imgui.set_next_item_width(100)
_, entry["history_trunc_limit"] = imgui.input_int("##hist", entry.get("history_trunc_limit", 900000))
imgui.unindent(20) imgui.unindent(20)
imgui.dummy(imgui.ImVec2(0, 4))
imgui.pop_id() imgui.pop_id()
for i in reversed(to_remove): for i in reversed(to_remove): self._editing_persona_preferred_models_list.pop(i)
self._editing_persona_preferred_models_list.pop(i)
if i in self._persona_pref_models_expanded:
del self._persona_pref_models_expanded[i]
imgui.end_child() imgui.end_child()
if imgui.button("Add Preferred Model"): # Custom Splitter
idx = len(self._editing_persona_preferred_models_list) imgui.button("###persona_splitter", imgui.ImVec2(-1, 4))
self._editing_persona_preferred_models_list.append({ if imgui.is_item_active():
"provider": self.current_provider, self._persona_split_v = max(0.1, min(0.9, self._persona_split_v + imgui.get_io().mouse_delta.y / total_h))
"model": self.current_model,
"temperature": 0.7,
"max_output_tokens": 4096,
"history_trunc_limit": 900000
})
self._persona_pref_models_expanded[idx] = True
imgui.dummy(imgui.ImVec2(0, 8)) imgui.dummy(imgui.ImVec2(0, 2))
imgui.separator() 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})
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("Tool Preset:") imgui.dummy(imgui.ImVec2(0, 2))
imgui.same_line() if imgui.begin_table("p_assign", 2):
t_preset_names = ["None"] + sorted(self.controller.tool_presets.keys()) imgui.table_setup_column("C1"); imgui.table_setup_column("C2"); imgui.table_next_row()
t_idx = t_preset_names.index(self._editing_persona_tool_preset_id) if getattr(self, '_editing_persona_tool_preset_id', '') in t_preset_names else 0 imgui.table_next_column(); imgui.text("Tool Preset:"); tn = ["None"] + sorted(self.controller.tool_presets.keys())
imgui.set_next_item_width(200) t_idx = tn.index(self._editing_persona_tool_preset_id) if getattr(self, '_editing_persona_tool_preset_id', '') in tn else 0
_, t_idx = imgui.combo("##ptoolpreset", t_idx, t_preset_names) imgui.set_next_item_width(-1); _, t_idx = imgui.combo("##ptp", t_idx, tn); self._editing_persona_tool_preset_id = tn[t_idx] if t_idx > 0 else ""
self._editing_persona_tool_preset_id = t_preset_names[t_idx] if t_idx > 0 else "" imgui.table_next_column(); imgui.text("Bias Profile:"); bn = ["None"] + sorted(self.controller.bias_profiles.keys())
b_idx = bn.index(self._editing_persona_bias_profile_id) if getattr(self, '_editing_persona_bias_profile_id', '') in bn else 0
imgui.set_next_item_width(-1); _, b_idx = imgui.combo("##pbp", b_idx, bn); self._editing_persona_bias_profile_id = bn[b_idx] if b_idx > 0 else ""
imgui.end_table()
imgui.same_line() if imgui.button("Manage Tools & Biases", imgui.ImVec2(-1, 0)): self.show_tool_preset_manager_window = True
imgui.text("Bias Profile:") imgui.dummy(imgui.ImVec2(0, 4)); imgui.separator(); imgui.text("System Prompt:")
imgui.same_line() imgui.begin_child("p_prompt_header", imgui.ImVec2(0, 30), False)
bias_names = ["None"] + sorted(self.controller.bias_profiles.keys()) imgui.text("Template:"); imgui.same_line(); p_pre = ["Select..."] + sorted(self.controller.presets.keys())
b_idx = bias_names.index(self._editing_persona_bias_profile_id) if getattr(self, '_editing_persona_bias_profile_id', '') in bias_names else 0
imgui.set_next_item_width(200)
_, b_idx = imgui.combo("##pbiasprofile", b_idx, bias_names)
self._editing_persona_bias_profile_id = bias_names[b_idx] if b_idx > 0 else ""
imgui.same_line()
if imgui.button("Manage Tools##p_tools"):
self.show_tool_preset_manager_window = True
imgui.dummy(imgui.ImVec2(0, 8))
imgui.separator()
imgui.dummy(imgui.ImVec2(0, 8))
imgui.text("System Prompt:")
imgui.text("Load from Preset:")
imgui.same_line()
prompt_presets = ["Select..."] + sorted(self.controller.presets.keys())
if not hasattr(self, "_load_preset_idx"): self._load_preset_idx = 0 if not hasattr(self, "_load_preset_idx"): self._load_preset_idx = 0
imgui.set_next_item_width(150) imgui.set_next_item_width(200); _, self._load_preset_idx = imgui.combo("##load_p", self._load_preset_idx, p_pre)
_, self._load_preset_idx = imgui.combo("##load_preset", self._load_preset_idx, prompt_presets) imgui.same_line();
imgui.same_line() if imgui.button("Apply"):
if imgui.button("Apply##apply_p"): if self._load_preset_idx > 0: self._editing_persona_system_prompt = self.controller.presets[p_pre[self._load_preset_idx]].system_prompt
if self._load_preset_idx > 0: imgui.same_line();
pname = prompt_presets[self._load_preset_idx] if imgui.button("Manage"): self.show_preset_manager_window = True
if pname in self.controller.presets: imgui.end_child()
p = self.controller.presets[pname] _, self._editing_persona_system_prompt = imgui.input_text_multiline("##pprompt", self._editing_persona_system_prompt, imgui.ImVec2(-1, h2))
self._editing_persona_system_prompt = p.system_prompt imgui.end_child()
self._load_preset_idx = 0
imgui.same_line() # Fixed Bottom Buttons
if imgui.button("Manage Prompts##p_prompts"):
self.show_preset_manager_window = True
_, self._editing_persona_system_prompt = imgui.input_text_multiline("##pprompt", self._editing_persona_system_prompt, imgui.ImVec2(-1, 150))
imgui.dummy(imgui.ImVec2(0, 8))
imgui.separator() imgui.separator()
imgui.dummy(imgui.ImVec2(0, 8)) if imgui.button("Save Persona", imgui.ImVec2(150, 0)):
if imgui.button("Save Persona", imgui.ImVec2(120, 0)):
if self._editing_persona_name.strip(): if self._editing_persona_name.strip():
try: try:
import copy 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))
save_models = copy.deepcopy(self._editing_persona_preferred_models_list) self.controller._cb_save_persona(persona, getattr(self, '_editing_persona_scope', 'project')); self.ai_status = f"Saved: {persona.name}"
except Exception as e: self.ai_status = f"Error: {e}"
persona = models.Persona( else: self.ai_status = "Name required"
name=self._editing_persona_name.strip(), imgui.same_line();
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=save_models,
)
self.controller._cb_save_persona(persona, getattr(self, '_editing_persona_scope', 'project'))
self.ai_status = f"Saved Persona: {persona.name}"
except Exception as e:
self.ai_status = f"Error saving persona: {e}"
import traceback
traceback.print_exc()
else:
self.ai_status = "Name required"
imgui.same_line()
if imgui.button("Delete", imgui.ImVec2(100, 0)): if imgui.button("Delete", imgui.ImVec2(100, 0)):
if not getattr(self, '_editing_persona_is_new', True) and self._editing_persona_name: if not getattr(self, '_editing_persona_is_new', True) and self._editing_persona_name:
self.controller._cb_delete_persona(self._editing_persona_name, getattr(self, '_editing_persona_scope', 'project')) self.controller._cb_delete_persona(self._editing_persona_name, getattr(self, '_editing_persona_scope', 'project'))
self.ai_status = f"Deleted Persona: {self._editing_persona_name}" self._editing_persona_name = ""; self._editing_persona_is_new = True
self._editing_persona_name = ""
self._editing_persona_is_new = True
if not is_embedded: if not is_embedded:
imgui.same_line() imgui.same_line();
if imgui.button("Close", imgui.ImVec2(100, 0)): if imgui.button("Close", imgui.ImVec2(100, 0)): self.show_persona_editor_window = False
self.show_persona_editor_window = False imgui.end_table()
finally:
imgui.end_child()
finally: finally:
if not is_embedded: if not is_embedded: imgui.end()
imgui.end()
def _render_projects_panel(self) -> None: def _render_projects_panel(self) -> None:
if self.perf_profiling_enabled: self.perf_monitor.start_component("_render_projects_panel") if self.perf_profiling_enabled: self.perf_monitor.start_component("_render_projects_panel")
proj_name = self.project.get("project", {}).get("name", Path(self.active_project_path).stem) proj_name = self.project.get("project", {}).get("name", Path(self.active_project_path).stem)