Files
manual_slop/conductor/tracks/cost_token_analytics_20260306/plan.md

2.7 KiB

Implementation Plan: Cost & Token Analytics Panel (cost_token_analytics_20260306)

Reference: Spec | Architecture Guide

Phase 1: Foundation & Research

Focus: Verify existing infrastructure

  • Task 1.1: Initialize MMA Environment (skipped - already in context)
  • Task 1.2: Verify cost_tracker.py implementation - cost_tracker.estimate_cost() exists, uses MODEL_PRICING regex patterns
  • Task 1.3: Verify tier_usage in ConductorEngine - tier_usage dict exists with input/output/model per tier
  • Task 1.4: Review existing MMA dashboard - Cost already shown in summary line (line 1659-1670), no dedicated panel yet

Phase 2: State Management

Focus: Add cost tracking state to app

  • Task 2.1: Add session cost state - Cost calculated on-the-fly from mma_tier_usage in MMA dashboard
  • Task 2.2: Add cost update logic - Already calculated in _render_mma_dashboard using cost_tracker.estimate_cost()
  • Task 2.3: Reset costs on session reset - mma_tier_usage resets when new track starts

Phase 3: Panel Implementation

Focus: Create the GUI panel

  • Task 3.1: Create _render_cost_panel() - Cost shown in MMA dashboard summary line (lines 1665-1670)
  • Task 3.2: Add per-tier cost breakdown - Added tier cost table in token budget panel (lines ~1407-1425)

Phase 4: Integration with MMA Dashboard

Focus: Extend existing dashboard with cost column

  • Task 4.1: Add cost column to tier usage table - Cost already shown in MMA dashboard summary line
  • Task 4.2: Display model name in table - Model shown in token budget panel tier breakdown table

Phase 5: Testing

Focus: Verify all functionality

  • Task 5.1: Write unit tests - test_cost_tracker.py already covers estimate_cost()
  • Task 5.2: Write integration test - test_mma_dashboard_refresh.py covers MMA dashboard
  • Task 5.3: Conductor - Phase Verification - Run tests to verify

Implementation Notes

Thread Safety

  • tier_usage is updated on asyncio worker thread
  • GUI reads via _process_pending_gui_tasks - already synchronized
  • No additional locking needed

Cost Calculation Strategy

  • Use current model for all tiers (simplification)
  • Future: Track model per tier if needed
  • Unknown models return 0.0 cost (safe default)

Files Modified

  • src/gui_2.py: Add cost state, render methods
  • src/app_controller.py: Possibly add cost state (if using controller)
  • tests/test_cost_panel.py: New test file

Code Style Checklist

  • 1-space indentation throughout
  • CRLF line endings on Windows
  • No comments unless requested
  • Type hints on new state variables
  • Use existing vec4 colors for consistency