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.
This commit is contained in:
ed
2026-06-25 19:01:29 -04:00
parent 08a5da9413
commit 2ba0aaae3c
2 changed files with 7 additions and 3 deletions
+5 -1
View File
@@ -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: