From 8cf8cfeb4eb68449aaecc5d267bfae915b370132 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 25 Jun 2026 20:10:04 -0400 Subject: [PATCH] refactor(gui_2): migrate CommsLogEntry consumers to direct field access Phase 3: CommsLogEntry Before: 3 .get('source_tier',...) sites + 1 half-measure in src/gui_2.py After: 0 Delta: -4 (expected: -5 per plan; the 5th site was app_controller.py:1930 which returns None for missing source_tier and cannot be migrated without breaking test_append_tool_log_dict_keys) Migrates the following CommsLogEntry-related sites in src/gui_2.py: 1. gui_2.py:1810 - cache filter source_tier (.get('source_tier', '')) 2. gui_2.py:1818 - cache filter source_tier (.get('source_tier', '')) 3. gui_2.py:5104 - render_comms_log_panel source_tier (.get('source_tier', 'main')) 4. gui_2.py:5106 - render_comms_log_panel ts (.get('ts', '00:00:00')) 5. gui_2.py:5107 - render_comms_log_panel direction (.get('direction', '??')) 6. gui_2.py:5110 - render_comms_log_panel model (.get('model', '?')) 7. gui_2.py:5802 - render_tool_calls_panel half-measure (subscript + 'in' check; entry['source_tier'] if 'source_tier' in entry else 'main') All migrated via: ce = CommsLogEntry.from_dict(entry) ce. # direct attribute access The dataclass default for source_tier is 'main', which preserves the fallback behavior for sites that had 'main' as the default. For sites with '' as the default (cache filters), the behavior change is benign because both '' and 'main' fail to match any non-trivial agent prefix. Notes: - The 'kind' field is NOT migrated because it has a legacy 'type' fallback ('kind' OR 'type') that the dataclass default doesn't preserve. - 'provider' and 'payload' are NOT on CommsLogEntry; they remain as entry.get(...) calls. - src/app_controller.py:1930 is NOT migrated because its no-default behavior (returns None) is asserted by test_append_tool_log_dict_keys. Tests: 16/16 pass (test_mma_agent_focus_phase1, test_comms_log_entry, test_gui2_events). --- src/gui_2.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index 351c343b..89f26cb8 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -1807,7 +1807,7 @@ def render_main_interface(app: App) -> None: if app.is_viewing_prior_session: app._comms_log_cache = app.prior_session_entries else: log_raw = list(app._comms_log) - if app.ui_focus_agent: app._comms_log_cache = [e for e in log_raw if e.get("source_tier", "").startswith(app.ui_focus_agent)] + if app.ui_focus_agent: app._comms_log_cache = [e for e in log_raw if CommsLogEntry.from_dict(e).source_tier.startswith(app.ui_focus_agent)] else: app._comms_log_cache = log_raw app._comms_log_dirty = False @@ -1815,7 +1815,7 @@ def render_main_interface(app: App) -> None: if app.is_viewing_prior_session: app._tool_log_cache = app.prior_tool_calls else: log_raw = list(app._tool_log) - if app.ui_focus_agent: app._tool_log_cache = [e for e in log_raw if e.get("source_tier", "").startswith(app.ui_focus_agent)] + if app.ui_focus_agent: app._tool_log_cache = [e for e in log_raw if CommsLogEntry.from_dict(e).source_tier.startswith(app.ui_focus_agent)] else: app._tool_log_cache = log_raw app._tool_log_dirty = False @@ -5096,12 +5096,13 @@ def render_comms_history_panel(app: App) -> None: imgui.push_id(f"comms_entry_{i}") i_display = i + 1 - ts = entry.get("ts", "00:00:00") - direction = entry.get("direction", "??") + ce = CommsLogEntry.from_dict(entry) + ts = ce.ts or "00:00:00" + direction = ce.direction or "??" kind = entry.get("kind", entry.get("type", "??")) provider = entry.get("provider", "?") - model = entry.get("model", "?") - tier = entry.get("source_tier", "main") + model = ce.model or "?" + tier = ce.source_tier payload = entry.get("payload", {}) if not payload and kind not in ("request", "response", "tool_call", "tool_result"): payload = entry # legacy @@ -5799,7 +5800,7 @@ def render_tool_calls_panel(app: App) -> None: app.show_windows["Text Viewer"] = True imgui.table_next_column() - imgui.text_colored(C_SUB(), f"[{entry['source_tier'] if 'source_tier' in entry else 'main'}]") + imgui.text_colored(C_SUB(), f"[{CommsLogEntry.from_dict(entry).source_tier}]") imgui.table_next_column() script_preview = script.replace("\n", " ")[:150]