# Specification: Fix GUI Crashes in Tool Preset Manager and Discussion Hub

## Overview
This track addresses several critical crashes in the immediate-mode GUI (`gui_2.py`) related to the Tool Preset Manager and the Discussion Hub. These issues include Python exceptions (`NameError`, `IndexError`) and underlying ImGui rendering assertion failures (`PopID() too many times`, `Must call EndChild() and not End()!`).

## Functional Requirements
- **Tool Preset Manager Fixes:**
  - Resolve the `NameError: name 'current_cat_tools' is not defined` when interacting with or modifying tool preset entries (e.g., changing approval from "auto" to "ask").
  - Fix the ImGui scope mismatch (`Must call EndChild() and not End()!`) in the `tp_scroll_2FED8981` child window.
- **Discussion Hub Fixes:**
  - Resolve the `IndexError: list index out of range` in `render_discussion_entries` that occurs when deleting a discussion entry.
  - Fix the associated ImGui scope mismatches (`Calling PopID() too many times!`) in the `HistoryChild_AB39D74A` window and tabs that trigger after the exception occurs.
- **Take Management Fixes:**
  - Fix the bug where clicking a Take tab fails to switch the active take and falls back to the original take, causing a 1-frame flicker.

## Non-Functional Requirements
- **ImGui Scope Safety:** Ensure all ImGui push/pop and begin/end pairs are correctly matched, even when exceptions are raised or lists are modified during rendering. The use of `imscope` context managers should be verified.
- **Code Style:** Fixes must adhere to the 1-space indentation rule for Python code and follow the "ImGui Defer Patterns" described in the code style guides.

## Acceptance Criteria
- [ ] Modifying a tool preset (e.g., changing the approval status of `ts_cpp` tools) does not raise a `NameError` or crash the application.
- [ ] Deleting a discussion entry removes the entry visually and does not raise an `IndexError`.
- [ ] Both panels can be interacted with, opened, and closed without triggering ImGui assertion failures.
- [ ] The `scripts/check_imgui_scopes.py` linter passes without new errors.

## Out of Scope
- Adding new features to the Tool Preset Manager or Discussion Hub.
- General refactoring of the GUI outside of fixing these specific crash points.