# Implementation Plan: Event-Driven API Metrics Updates ## Phase 1: Event Infrastructure & Test Setup [checkpoint: 776f4e4] Define the event mechanism and create baseline tests to ensure we don't break data accuracy. - [x] Task: Create `tests/test_api_events.py` to verify the new event emission logic in isolation. cd3f3c8 - [x] Task: Implement a simple `EventEmitter` or `Signal` class (if not already present) to handle decoupled communication. cd3f3c8 - [x] Task: Instrument `ai_client.py` with the event system, adding placeholders for the key lifecycle events. cd3f3c8 - [ ] Task: Conductor - User Manual Verification 'Phase 1: Event Infrastructure & Test Setup' (Protocol in workflow.md) ## Phase 2: Client Instrumentation (API Lifecycle) [checkpoint: e24664c] Update the AI client to emit events during actual API interactions. - [x] Task: Implement event emission for Gemini and Anthropic request/response cycles in `ai_client.py`. 20ebab5 - [x] Task: Implement event emission for tool/function calls and stream processing. 20ebab5 - [x] Task: Verify via tests that events carry the correct payload (token counts, session metadata). 20ebab5 - [x] Task: Conductor - User Manual Verification 'Phase 2: Client Instrumentation (API Lifecycle)' (Protocol in workflow.md) e24664c ## Phase 3: GUI Integration & Decoupling [checkpoint: 8caebbd] Connect the UI to the event system and remove polling logic. - [x] Task: Update `gui.py` to subscribe to API events and trigger metrics UI refreshes only upon event receipt. 2dd6145 - [x] Task: Audit the `gui.py` render loop and remove all per-frame metrics calculations or display updates. 2dd6145 - [x] Task: Verify that UI performance improves (reduced CPU/frame time) while metrics remain accurate. 2dd6145 - [x] Task: Conductor - User Manual Verification 'Phase 3: GUI Integration & Decoupling' (Protocol in workflow.md) 8caebbd ## Phase: Review Fixes - [x] Task: Apply review suggestions 66f728e