# Implementation Plan: Feature Bleed Cleanup

Architecture reference: [docs/guide_architecture.md](../../../docs/guide_architecture.md)

---

## Phase 1: Dead Code Removal [checkpoint: be7174c]
Focus: Delete the two confirmed dead code blocks — no behavior change, pure deletion.

- [x] Task 1.1: In `gui_2.py`, delete the first `_render_comms_history_panel` definition. 2e9c995
  - **Location**: Lines 3041-3073 (use `py_get_code_outline` to confirm current line numbers before editing).
  - **What**: The entire method body from `def _render_comms_history_panel(self) -> None:` through `imgui.end_child()` and the following blank line. The live version begins at ~line 3435 after this deletion shifts lines.
  - **How**: Use `set_file_slice` to delete lines 3041-3073 (replace with empty string). Then run `py_get_code_outline` to confirm only one `_render_comms_history_panel` remains.
  - **Verify**: `grep -n "_render_comms_history_panel" gui_2.py` should show exactly 2 hits: the `def` line and the call site in `_gui_func`.

- [x] Task 1.2: In `gui_2.py` `__init__`, delete the duplicate state variable assignments. e28f89f
  - **Location**: Second occurrences of `ui_conductor_setup_summary`, `ui_new_track_name`, `ui_new_track_desc`, `ui_new_track_type`. Currently at lines 308-311 (grep to confirm exact lines before editing: `grep -n "ui_conductor_setup_summary" gui_2.py`).
  - **What**: Delete these 4 lines. The first correct assignments remain at lines 218-221.
  - **How**: Use `set_file_slice` to remove lines 308-311 (replace with empty string).
  - **Verify**: Each variable should appear exactly once in `__init__` (grep to confirm).

- [x] Task 1.3: Write/run tests to confirm no regressions. 535667b
  - Run `uv run pytest tests/ -x -q` and confirm all tests pass.
  - Run `uv run python -c "from gui_2 import App; print('import ok')"` to confirm no syntax errors.

- [x] Task 1.4: Conductor — User Manual Verification
  - Start the app with `uv run python gui_2.py` and confirm it launches without error.
  - Open "Operations Hub" → "Comms History" tab and confirm the comms panel renders (color legend visible).

---

## Phase 2: Menu Bar Consolidation [checkpoint: 15fd786]
Focus: Remove the dead inline menubar block and add a working Quit item to `_show_menus`.

- [x] Task 2.1: Delete the dead `begin_main_menu_bar()` block from `_gui_func`. b0f5a5c
  - **Location**: `gui_2.py` lines 1679-1705 (the comment `# ---- Menubar` through `imgui.end_main_menu_bar()`). Use `get_file_slice(1676, 1712)` to confirm exact boundaries before editing.
  - **What**: Delete the `# ---- Menubar` comment line and the entire `if imgui.begin_main_menu_bar(): ... imgui.end_main_menu_bar()` block (~27 lines total). The `# --- Hubs ---` comment and hub rendering that follows must be preserved.
  - **How**: Use `set_file_slice` to replace lines 1679-1705 with a single blank line.
  - **Verify**: `grep -n "begin_main_menu_bar" gui_2.py` returns 0 hits.

- [x] Task 2.2: Add working "Quit" to `_show_menus`. 340f44e
  - **Location**: `gui_2.py` `_show_menus` method (lines 1620-1647 — confirm with `py_get_definition`).
  - **What**: Before the existing `if imgui.begin_menu("Windows"):` line, insert:
    ```python
    if imgui.begin_menu("manual slop"):
        if imgui.menu_item("Quit", "Ctrl+Q", False)[0]:
            self.runner_params.app_shall_exit = True
        imgui.end_menu()
    ```
  - **Note**: `self.runner_params` is set in `run()` before `immapp.run()` is called, so it is valid here.
  - **How**: Use `set_file_slice` or `Edit` to insert the block before the "Windows" menu.
  - **Verify**: Launch app, confirm "manual slop" > "Quit" appears in menubar and clicking it closes the app cleanly.

- [x] Task 2.3: Write/run tests. acd7c05
  - Run `uv run pytest tests/ -x -q`.

- [x] Task 2.4: Conductor — User Manual Verification
  - Launch app. Confirm menubar has: "manual slop" (with Quit), "Windows", "Project".
  - Confirm "View" menu is gone (was dead duplicate of "Windows").
  - Confirm Quit closes the app.

---

## Phase 3: Token Budget Layout Fix [checkpoint: 0d081a2]
Focus: Give the token budget panel its own collapsing header in AI Settings; remove the double label from the provider panel.

- [x] Task 3.1: Remove the double label + embedded call from `_render_provider_panel`. 6097368
  - **Location**: `gui_2.py` `_render_provider_panel` (lines ~2687-2746 — use `py_get_definition` to confirm). The block to remove is:
    ```python
    imgui.text("Token Budget:")
    imgui.separator()
    imgui.text("Token Budget")
    self._render_token_budget_panel()
    ```
    These are 4 consecutive lines at the end of the method (before `if self._gemini_cache_text:`).
  - **What**: Delete those 4 lines. The `if self._gemini_cache_text:` block that follows them must be preserved in place.
  - **How**: Use `Edit` with `old_string` set to those exact 4 lines.
  - **Verify**: `_render_provider_panel` ends with the `if self._gemini_cache_text:` block and no "Token Budget" text labels.

- [x] Task 3.2: Add `collapsing_header("Token Budget")` to AI Settings in `_gui_func`. 6097368
  - **Location**: `gui_2.py` `_gui_func`, AI Settings window block (currently lines ~1719-1723 — `get_file_slice(1715, 1730)` to confirm). Current content:
    ```python
    if imgui.collapsing_header("Provider & Model"):
        self._render_provider_panel()
    if imgui.collapsing_header("System Prompts"):
        self._render_system_prompts_panel()
    ```
  - **What**: Add after the System Prompts header:
    ```python
    if imgui.collapsing_header("Token Budget"):
        self._render_token_budget_panel()
    ```
  - **How**: Use `Edit` to insert after the `_render_system_prompts_panel()` call.
  - **Verify**: AI Settings window now shows three collapsing sections: "Provider & Model", "System Prompts", "Token Budget".

- [x] Task 3.3: Write/run tests. bd3d0e7
  - Run `uv run pytest tests/ -x -q`.

- [x] Task 3.4: Conductor — User Manual Verification
  - Launch app. Open "AI Settings" window.
  - Confirm "Token Budget" appears as a collapsing header (expand it — panel renders correctly).
  - Confirm "Provider & Model" section no longer shows any "Token Budget" label.

---

## Phase Completion Checkpoint
After all phases pass manual verification:
- Run `uv run pytest tests/ -x -q` one final time.
- Commit: `fix(bleed): remove dead comms panel dup, consolidate menubar, fix token budget layout`
- Update TASKS.md to mark this track complete.
- Update JOURNAL.md with What/Why/How/Issues/Result.
