feat: add file edit diff progress view

Capture file edit snapshots through runner tool lifecycle hooks and render unified diffs in the WebUI with folding and truncation controls.
This commit is contained in:
chengyongru
2026-07-09 10:42:43 +08:00
committed by Xubin Ren
parent 207813d3b5
commit 7768672c5b
40 changed files with 2224 additions and 1753 deletions
+43 -9
View File
@@ -1525,16 +1525,50 @@ def replay_transcript_to_ui_messages(
)
):
return i
existing_tool_events = candidate.get("toolEvents")
if isinstance(existing_tool_events, list):
for event in existing_tool_events:
if not isinstance(event, dict):
continue
key = _tool_event_file_edit_key(event)
if key and key in incoming_tool_event_keys:
return i
return None
def trace_message_is_empty(message: dict[str, Any]) -> bool:
traces = message.get("traces")
if isinstance(traces, list):
has_trace = any(isinstance(trace, str) and trace.strip() for trace in traces)
else:
has_trace = bool(str(message.get("content") or "").strip())
return (
message.get("kind") == "trace"
and not has_trace
and not message.get("toolEvents")
and not message.get("fileEdits")
and not message.get("media")
)
def strip_covered_file_edit_tool_hints_from_recent_messages(
edits: list[dict[str, Any]],
turn_fields: dict[str, Any],
) -> None:
nonlocal messages
if not edits:
return
next_messages = list(messages)
changed = False
for i in range(len(next_messages) - 1, -1, -1):
candidate = next_messages[i]
if candidate.get("role") == "user":
break
if candidate.get("kind") != "trace":
continue
if not _same_turn(candidate, turn_fields):
continue
cleaned = _strip_covered_file_edit_tool_hints(candidate, edits)
if cleaned is candidate:
continue
changed = True
if trace_message_is_empty(cleaned):
next_messages.pop(i)
else:
next_messages[i] = cleaned
if changed:
messages = next_messages
def upsert_file_edits(
edits: list[dict[str, Any]],
idx: int,
@@ -1549,12 +1583,12 @@ def replay_transcript_to_ui_messages(
segment = _new_activity_segment(activate=False)
active_file_edit_segment_id = segment
demote_interrupted_assistant(segment)
strip_covered_file_edit_tool_hints_from_recent_messages(edits, turn_fields)
target_index = find_file_edit_trace_index(segment, edits)
if target_index is not None:
last = messages[target_index]
segment = str(last.get("activitySegmentId") or segment or _new_activity_segment(activate=False))
active_file_edit_segment_id = segment
last = _strip_covered_file_edit_tool_hints(last, edits)
else:
if not segment:
segment = _new_activity_segment(activate=False)