PromptRunner.Rendering.Studio.Diff (PromptRunnerSDK v0.10.0)

Copy Markdown View Source

Showing what a tool changed on disk.

There are two cases, and they are not the same thing.

The patch is in the event. A Claude Edit carries old_string and new_string; a Write carries the whole content. The diff is derivable from the event alone — no filesystem access, no ambiguity, and it stays correct even if the file changed again afterwards.

Only the path is in the event. A Codex file_change item and an Antigravity replace_file_content name the file and the kind of change and nothing else. The honest options are a git diff on that path or a stat line. A git diff is cheap and accurate at the moment it runs — but it shows the file's current state, which after several edits is not the diff of that one tool call.

The rule: never present a reconstructed diff as if it were the tool's own patch. At :stat, show the path and the change kind. At :full, render the event's patch where one exists, and where one does not, label the rendered git diff as the file's current state rather than as that call's change.

Summary

Functions

The rendered diff body for a tool call, as iodata.

The line counts for a tool call's change, or nil when the event does not carry enough to compute them.

A +12 −3 suffix for a summary line, or "" when there is nothing to count.

Types

stat()

@type stat() :: %{added: non_neg_integer(), removed: non_neg_integer()}

Functions

render(tool_info, opts \\ [])

@spec render(
  map(),
  keyword()
) :: iodata()

The rendered diff body for a tool call, as iodata.

Options:

  • :color — colourize (default true)
  • :indent — leading spaces (default 4)
  • :line_budget — maximum body lines before truncation (default 60)
  • :cwd — where to run git diff for a path-only change

Returns [] when there is nothing to show. Never silently truncates: a truncated diff that looks complete is worse than no diff.

stat(tool_info)

@spec stat(map()) :: stat() | nil

The line counts for a tool call's change, or nil when the event does not carry enough to compute them.

stat_suffix(tool_info)

@spec stat_suffix(map()) :: String.t()

A +12 −3 suffix for a summary line, or "" when there is nothing to count.