Skip to main content

Module diff

Module diff 

Source
Expand description

Unified-diff rendering for file-modifying tools.

Produces a compact, user-facing unified diff (with +N -M stats and a line cap) so channel adapters and the web UI can show exactly what an edit_file / write_file call changed, instead of a bare success line.

Structs§

UnifiedDiff
A rendered unified diff plus its summary stats.

Constants§

DEFAULT_DIFF_MAX_LINES
Default cap on rendered diff lines (matching the 120-line convention popularized by Grok Build’s diff view).
FILE_DIFF_METADATA_KEY
Key under which file-modifying tools attach their diff payload to ToolResult::metadata. Shared so the producer (tools) and consumers (tool executor → AgentEvent::FileDiff) cannot silently desync.

Functions§

file_diff_metadata
Build the metadata payload for a file edit diff.
format_diff_chat_message
Format a chat-facing message for a file diff: a one-line header with the path and +N -M stats, followed by a fenced ```diff block.
unified_diff
Compute a unified diff between old and new, capped at max_lines rendered lines. Returns None when the contents are identical.