# Implementation Plan: Advanced Log Management and Session Restoration

## Phase 1: Storage Optimization (Offloading Data) [checkpoint: de5b152]
- [x] Task: Implement file-based offloading for scripts and tool outputs. 7063bea
    - [ ] Update `src/session_logger.py` to include `log_tool_output(session_id, output)` which saves output to a unique file in the session directory and returns the filename.
    - [ ] Modify `src/session_logger.py:log_tool_call` to ensure scripts are consistently saved and return a unique filename/ID.
    - [ ] Update `src/app_controller.py` to use these unique IDs/filenames in the `payload` of comms and tool logs instead of raw content.
- [x] Task: Verify that logs are smaller and scripts/outputs are correctly saved to the session directory. 7063bea
- [ ] Task: Conductor - User Manual Verification 'Phase 1: Storage Optimization' (Protocol in workflow.md)

## Phase 2: Session-Level Restoration & UI Relocation [checkpoint: 1b3fc5b]
- [x] Task: Relocate the "Load Log" button. 72bb2ce
    - [ ] Remove the "Load Log" button from `_render_comms_history_panel` in `src/gui_2.py`.
    - [ ] Add the "Load Log" button to the "Log Management" panel in `src/gui_2.py`.
- [x] Task: Rework `cb_load_prior_log` for session-level loading. 1b3fc5b
    - [ ] Update `src/app_controller.py:cb_load_prior_log` to allow selecting a session directory or the main session log file.
    - [ ] Implement logic to load all related logs (comms, mma, tools) for that session.
    - [ ] Ensure that for entries referencing external files (scripts/outputs), the content is loaded on-demand or during the restoration process.
- [x] Task: Implement "Historical Replay" UI mode. 1b3fc5b
    - [x] In `src/gui_2.py`, implement logic to tint the UI (as already partially done for comms) when `is_viewing_prior_session` is True.
    - [x] Populate `disc_entries`, `_comms_log`, and MMA Dashboard states from the loaded session logs.
    - [x] Harden `cb_load_prior_log` for legacy compatibility and reference resolution. bbe0209
    - [x] Fix `PopStyleColor()` crash in `_gui_func` using frame-scoped flag. 27b98ff
- [ ] Task: Conductor - User Manual Verification 'Phase 2: Session-Level Restoration' (Protocol in workflow.md)

## Phase 3: Diagnostic Log & Discussion Cleanup
- [x] Task: Clean up discussion history and implement Diagnostic Tab. 8e02c1e
    - [ ] Add `self.diagnostic_log` (a list of transient messages) to `AppController`.
    - [ ] Update `src/app_controller.py:_on_performance_alert` to append to `self.diagnostic_log` instead of `disc_entries`.
    - [ ] Update `src/ai_client.py` (and other areas) to redirect "SYSTEM WARNING" and similar performance-related messages to the diagnostic log via a new event type.
    - [ ] Add a "Diagnostics" tab to the Log Management panel in `src/gui_2.py` to render `self.diagnostic_log`.
    - [ ] Ensure `diagnostic_log` is NOT persisted to `manual_slop.toml` or restored during session loads.
- [ ] Task: Conductor - User Manual Verification 'Phase 3: Diagnostic Log & Cleanup' (Protocol in workflow.md)

## Phase 4: MMA Log Integration & Filtering [checkpoint: c3e0cb3]
- [x] Task: Improve MMA log visibility and filtering. c3e0cb3
    - [x] Ensure MMA sub-agent `log_comms` calls include sufficient metadata (tier, role) for filtering.
    - [x] Update `_render_comms_history_panel` in `src/gui_2.py` to ensure MMA logs are clearly distinct and correctly filtered based on existing UI toggles.
- [x] Task: Final end-to-end verification of session restoration and log management. c3e0cb3
- [ ] Task: Conductor - User Manual Verification 'Phase 4: MMA Log Integration' (Protocol in workflow.md)
