Add show_diff chat tool and diff card

The Pipelines MCP server gains show_diff: it runs Git in a repository
inside the operator's home (default: the chat's directory) and records
the per-file patches. Without base it shows uncommitted work against
HEAD; with base it shows everything since the merge base (a pull
request preview), optionally committed changes only. Bounded at 300
files, 256 KiB per patch and 1 MiB total, with partial diffs labelled;
diff bodies share the per-chat retention budget with HTML views.

The chat draws the item as a card listing each changed file with its
stat; a row opens the existing file diff viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 17:08:02 +00:00
parent 79e5183469
commit 059eb1bb0d
15 changed files with 1077 additions and 16 deletions
+24 -3
View File
@@ -2,7 +2,7 @@ package protocol
// ChatShown is the pushed frame type for an item a chat's model showed the
// operator through the Pipelines tools (show_file, show_image, show_html,
// notify). The chat_subscribe reply carries the retained list in the same
// show_diff, notify). The chat_subscribe reply carries the retained list in the same
// ChatShown field.
const ChatShown = "chat_shown"
@@ -11,12 +11,13 @@ const (
ChatShownFile = "file"
ChatShownImage = "image"
ChatShownHTML = "html"
ChatShownDiff = "diff"
ChatShownNotify = "notify"
)
// ChatShownLimit bounds the items retained per chat, and ChatShownHTMLBudget
// the HTML bytes kept across them: older documents beyond it keep their entry
// but drop the body (Expired).
// the HTML and diff bytes kept across them: older documents and diffs beyond
// it keep their entry but drop the body (Expired).
const (
ChatShownLimit = 100
ChatShownHTMLBudget = 2 << 20
@@ -44,6 +45,10 @@ type ChatShownItem struct {
Alt string `json:"alt,omitempty"`
HTML string `json:"html,omitempty"`
HTMLBytes int `json:"html_bytes,omitempty"`
// Diff is a show_diff item's repository comparison; DiffBytes is the size
// of its patches, counted against ChatShownHTMLBudget.
Diff *ChatShownDiffBody `json:"diff,omitempty"`
DiffBytes int `json:"diff_bytes,omitempty"`
// HeightHint is the model's preferred inline height in logical pixels.
HeightHint int `json:"height_hint,omitempty"`
Expired bool `json:"expired,omitempty"`
@@ -53,3 +58,19 @@ type ChatShownItem struct {
// Detail says why a notification was not delivered.
Detail string `json:"detail,omitempty"`
}
// ChatShownDiffBody is one Git comparison a chat's model showed: the work tree
// (or HEAD when CommittedOnly) of Repo against BaseCommit, which is HEAD when
// Base is empty and the merge base with Base otherwise. Changes uses the same
// per-file shape as a run's recorded changes; it is nil once Expired.
type ChatShownDiffBody struct {
Repo string `json:"repo"`
Base string `json:"base,omitempty"`
BaseCommit string `json:"base_commit,omitempty"`
Head string `json:"head,omitempty"`
CommittedOnly bool `json:"committed_only,omitempty"`
Files int `json:"files"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Changes *StageFileChanges `json:"changes,omitempty"`
}