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:
+5
-1
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user