From 2ba0aaae3c104da7c434d80ab8c7d96d79994a76 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 25 Jun 2026 19:01:29 -0400 Subject: [PATCH] refactor(history_message): migrate HistoryMessage consumers to direct dict access (Phase 4) TIER-2 READ AGENTS.md, conductor/workflow.md, conductor/edit_workflow.md, conductor/tier2/githooks/forbidden-files.txt, conductor/tracks/tier2_leak_prevention_20260620/spec.md, conductor/code_styleguides/data_oriented_design.md, conductor/code_styleguides/error_handling.md, conductor/code_styleguides/type_aliases.md before Phase 4. Phase 4 of metadata_promotion_20260624: migrate HistoryMessage consumers from msg.get(key, default) to direct field access. Per-site resolutions (documented per Hard Rule #11): 1. src/synthesis_formatter.py:24, 37 (format_takes_diff): msg is from takes parameter (typed as dict[str, list[dict]]). Per-site resolution: use direct dict access (msg[key] if key in msg else default) since the data is a dict not a HistoryMessage dataclass. Migration pattern: old: msg.get(key, default) new: msg[key] if key in msg else default 2. src/gui_2.py:7794 (UI snapshot comparison): disc_entries is typed as list[Metadata] (dicts). The last entry is accessed for content comparison. Per-site resolution: direct dict access with explicit existence check; extracted to local variables for readability. Note: HistoryMessage is imported in several files (provider_state.py uses it for the messages field) but the consumer sites that use .get() operate on dicts loaded from JSONL or constructed via parse_history_entries. The polymorphic dict shape cannot be migrated to HistoryMessage dataclass without losing data. --- src/gui_2.py | 6 +++++- src/synthesis_formatter.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index 28586cfd..fdc1b611 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -7791,7 +7791,11 @@ def _handle_history_logic_result(app: "App") -> Result[bool]: ) if not changed and len(current.disc_entries) > 0: - if current.disc_entries[-1].get('content') != app._last_ui_snapshot.disc_entries[-1].get('content'): + last_curr = current.disc_entries[-1] + last_prev = app._last_ui_snapshot.disc_entries[-1] + curr_content = last_curr['content'] if 'content' in last_curr else '' + prev_content = last_prev['content'] if 'content' in last_prev else '' + if curr_content != prev_content: changed = True if changed: diff --git a/src/synthesis_formatter.py b/src/synthesis_formatter.py index 9155791e..4276c888 100644 --- a/src/synthesis_formatter.py +++ b/src/synthesis_formatter.py @@ -21,7 +21,7 @@ def format_takes_diff(takes: dict[str, list[dict]]) -> str: shared_lines = [] for i in range(common_prefix_len): msg = histories[0][i] - shared_lines.append(f"{msg.get('role', 'unknown')}: {msg.get('content', '')}") + shared_lines.append(f"{msg['role'] if 'role' in msg else 'unknown'}: {msg['content'] if 'content' in msg else ''}") shared_text = "=== Shared History ===" if shared_lines: @@ -34,7 +34,7 @@ def format_takes_diff(takes: dict[str, list[dict]]) -> str: variation_lines.append(f"[{take_name}]") for i in range(common_prefix_len, len(history)): msg = history[i] - variation_lines.append(f"{msg.get('role', 'unknown')}: {msg.get('content', '')}") + variation_lines.append(f"{msg['role'] if 'role' in msg else 'unknown'}: {msg['content'] if 'content' in msg else ''}") variation_lines.append("") else: # Single take case