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:
@@ -83,8 +83,8 @@ func (s *Store) BindChatToolToken(ctx context.Context, token, scope string) erro
|
||||
}
|
||||
|
||||
// AppendChatShownItem records one shown item and applies the retention bounds:
|
||||
// at most protocol.ChatShownLimit items per chat, and HTML bodies only for the
|
||||
// newest documents within protocol.ChatShownHTMLBudget.
|
||||
// at most protocol.ChatShownLimit items per chat, and HTML and diff bodies only
|
||||
// for the newest documents within protocol.ChatShownHTMLBudget.
|
||||
func (s *Store) AppendChatShownItem(ctx context.Context, sessionID string, item protocol.ChatShownItem) error {
|
||||
payload, err := json.Marshal(item)
|
||||
if err != nil {
|
||||
@@ -109,15 +109,27 @@ SELECT id FROM chat_shown_items WHERE session_id=? ORDER BY created_at DESC, row
|
||||
budget := protocol.ChatShownHTMLBudget
|
||||
for i := len(items) - 1; i >= 0; i-- {
|
||||
current := items[i]
|
||||
if current.Kind != protocol.ChatShownHTML || current.Expired {
|
||||
if current.Expired {
|
||||
continue
|
||||
}
|
||||
if len(current.HTML) <= budget {
|
||||
budget -= len(current.HTML)
|
||||
var size int
|
||||
switch {
|
||||
case current.Kind == protocol.ChatShownHTML:
|
||||
size = len(current.HTML)
|
||||
case current.Kind == protocol.ChatShownDiff && current.Diff != nil && current.Diff.Changes != nil:
|
||||
size = current.DiffBytes
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if size <= budget {
|
||||
budget -= size
|
||||
continue
|
||||
}
|
||||
budget = 0
|
||||
current.HTML, current.Expired = "", true
|
||||
if current.Diff != nil {
|
||||
current.Diff.Changes = nil
|
||||
}
|
||||
data, err := json.Marshal(current)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user