Files
pipelines/internal/chattools/tools.go
T
alan d275ffe643 Chat tools: follow-up ids, cancel_followup, run-triggered follow-ups, show_html warnings
- schedule_followup returns the follow-up id and lists pending follow-ups;
  count-then-queue is serialised so the 3-pending bound holds under
  concurrent calls.
- cancel_followup {id} removes one of the chat's undelivered follow-ups.
- schedule_followup {run_id, on: finished|attention} queues a durable
  follow-up (7-day deadline) that is released with the run's state when the
  run ends or waits on a human; run must exist and not already meet the
  condition; watches are re-armed from the restored queue after a restart.
- show_html results warn about scripts, remote resources (blocked by the
  sandbox) and missing dark-mode support.
- The ambiguous-call error advice fits each tool instead of always
  suggesting a different title.
- references/chat.md and the SKILL.md chat paragraph document the above, and
  questions are no longer described as Claude-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:24:12 +00:00

219 lines
14 KiB
Go

package chattools
// The tool names, as the MCP server lists them.
const (
ToolShowFile = "show_file"
ToolShowImage = "show_image"
ToolShowHTML = "show_html"
ToolShowDiff = "show_diff"
ToolShowRun = "show_run"
ToolNotify = "notify"
// ToolScheduleFollowup queues a prompt into the calling chat for later.
ToolScheduleFollowup = "schedule_followup"
// ToolCancelFollowup removes a follow-up this chat scheduled.
ToolCancelFollowup = "cancel_followup"
)
// MaxHTMLBytes bounds one show_html document. A larger one is refused, never
// truncated: a cut document would render as something the model did not write.
const MaxHTMLBytes = 512 << 10
// The shown-file bounds: a file up to MaxSnapshotBytes is copied when shown,
// and a web image up to MaxFetchedImageBytes is fetched by Pipelines.
const (
MaxSnapshotBytes = 5 << 20
MaxFetchedImageBytes = 10 << 20
)
// The schedule_followup bounds.
const (
MinFollowupMinutes = 1
MaxFollowupMinutes = 7 * 24 * 60
MaxPendingFollowups = 3
MaxFollowupTextBytes = 8 << 10
// A run-triggered follow-up (run_id with on) is delivered when the run
// reaches the condition, or after MaxFollowupMinutes at the latest.
FollowupOnFinished = "finished"
FollowupOnAttention = "attention"
)
// IsTool reports whether name is one of the Pipelines tools.
func IsTool(name string) bool {
switch name {
case ToolShowFile, ToolShowImage, ToolShowHTML, ToolShowDiff, ToolShowRun, ToolNotify, ToolScheduleFollowup, ToolCancelFollowup:
return true
}
return false
}
// Instructions is the MCP initialize instructions text.
const Instructions = "These tools act on Pipelines, the app the operator reads this chat in, not on your workspace. " +
"Use show_file / show_image instead of telling the operator a path to open, show_html for diagrams, charts or small visual views, " +
"show_diff when the operator asks to see changes or a diff (for example before submitting a pull request), " +
"and notify only for something the operator should know mid-turn or after work the turn does not wait for: " +
"Pipelines already notifies them when your reply ends and when you ask a question or need an approval, so do not notify for those " +
"(a notify replaces this turn's end-of-reply notification). It reaches every Pipelines app they are signed in to and their phone, " +
"and clears everywhere once they open the chat. " +
"Use show_run to follow a pipeline run live in the chat, and schedule_followup to come back to this chat later (at a time, or when a run finishes or needs the operator; cancel_followup removes one). " +
"Every show_* result names the shown item's id: pass it as replace to update that card instead of adding another. " +
"Your thinking is not shown to the operator: before asking them a question (for example with AskUserQuestion), " +
"write what you found and why you are asking as a normal message, because the question form shows only the question and its options."
type toolDefinition struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description"`
InputSchema map[string]any `json:"inputSchema"`
Annotations map[string]any `json:"annotations,omitempty"`
}
func stringProperty(description string) map[string]any {
return map[string]any{"type": "string", "description": description}
}
func objectSchema(required []string, properties map[string]any) map[string]any {
return map[string]any{"type": "object", "properties": properties, "required": required, "additionalProperties": false}
}
// replaceProperty is the optional id of an earlier shown item to update.
func replaceProperty() map[string]any {
return stringProperty("Optional id of an item you showed earlier in this chat (from that call's result): " +
"the card is updated in place instead of a new one being added. It must be the same kind of item.")
}
// definitions is the tools/list result, in a fixed order.
func definitions() []toolDefinition {
return []toolDefinition{
{
Name: ToolShowFile,
Title: "Show a file in the chat",
Description: "Show the operator an existing file from this machine directly in the Pipelines chat: images appear inline, " +
"documents (PDF, Markdown, text, CSV, HTML, and others) as a preview card they can tap to open or download. " +
"Use this instead of telling the operator a path to navigate to. The file must be inside the operator's home directory. " +
"A relative path is resolved against the chat's working directory. " +
"A file up to 5 MiB is copied when shown, so the card keeps showing that version; a larger one stays linked " +
"and the card says when it changed or no longer exists. The result names the item's id for replace.",
InputSchema: objectSchema([]string{"path"}, map[string]any{
"path": stringProperty("Absolute path, ~/path, or a path relative to the chat's working directory."),
"title": stringProperty("Optional short caption shown above the file."),
"replace": replaceProperty(),
}),
Annotations: map[string]any{"readOnlyHint": true, "openWorldHint": false},
},
{
Name: ToolShowImage,
Title: "Show an image in the chat",
Description: "Show the operator an image inline in the Pipelines chat, from a file on this machine (inside the operator's home) " +
"or from an https:// URL. Pipelines downloads a URL itself (public https hosts only, at most 10 MiB, image types only) " +
"and keeps a copy, so the operator sees it even where the host refuses other sites; a failed download is reported " +
"to you and nothing is shown. The result names the item's id for replace.",
InputSchema: objectSchema([]string{"url_or_path"}, map[string]any{
"url_or_path": stringProperty("An https:// image URL, or a file path as for show_file."),
"title": stringProperty("Optional short caption."),
"alt": stringProperty("Optional description of the image for accessibility."),
"replace": replaceProperty(),
}),
Annotations: map[string]any{"readOnlyHint": true},
},
{
Name: ToolShowHTML,
Title: "Show an HTML view in the chat",
Description: "Render a self-contained HTML or SVG document inline in the Pipelines chat: diagrams, charts, tables, small visual views. " +
"It is shown in a sandbox with no scripts, no network and no access to the app: use inline CSS and inline SVG, " +
"<details> for expandable parts and CSS :hover for interaction; JavaScript does not run and external resources do not load. " +
"A document that supports dark mode follows the operator's light or dark theme: style for both with " +
"@media (prefers-color-scheme: dark), a color-scheme declaration or light-dark() colors (with color-scheme, " +
"unstyled text and the page use the theme's Canvas/CanvasText). A document without any of these is always shown light, on white. " +
"The operator can open it full screen. At most 512 KiB. The result names the item's id: pass it as replace to update the view.",
InputSchema: objectSchema([]string{"html"}, map[string]any{
"html": stringProperty("The complete HTML (or a bare <svg>) document."),
"title": stringProperty("Optional short caption."),
"height_hint": map[string]any{"type": "integer", "description": "Optional preferred inline height in logical pixels (120-600)."},
"replace": replaceProperty(),
}),
Annotations: map[string]any{"readOnlyHint": true, "openWorldHint": false},
},
{
Name: ToolShowDiff,
Title: "Show a Git diff in the chat",
Description: "Show the operator the changes in a Git repository on this machine as a diff card in the Pipelines chat: " +
"every changed file with its added and removed lines, each opening the app's diff viewer. " +
"Use it when the operator asks to see the diff or the changes, for example before a pull request is submitted. " +
"Pipelines runs Git itself, so do not paste the diff. Without base it shows uncommitted work (staged, unstaged and untracked files) against HEAD. " +
"With base (the pull request's target branch, such as main or origin/main) it shows everything since the branch left base, " +
"which is what the pull request would contain, plus uncommitted work unless committed_only is true. " +
"With head (a branch or commit, such as pipelines/run-123) it compares that revision instead of the working tree: " +
"against base when given (everything since head left base), else against HEAD. paths limits the diff to those files, " +
"directories or globs inside the repository. " +
"The repository must be inside the operator's home directory. Very large diffs are shown partially and say so.",
InputSchema: objectSchema([]string{}, map[string]any{
"path": stringProperty("Optional repository directory: absolute, ~/path, or relative to the chat's working directory. Defaults to the chat's working directory."),
"base": stringProperty("Optional branch, tag or commit to compare against, such as main or origin/main. Omit to show uncommitted changes."),
"head": stringProperty("Optional branch, tag or commit to show instead of the working tree, such as pipelines/run-123."),
"paths": map[string]any{"type": "array", "items": map[string]any{"type": "string"}, "description": "Optional repository-relative files, directories or globs (such as internal/server or *.go) to limit the diff to; at most 50."},
"committed_only": map[string]any{"type": "boolean", "description": "Only with base: show the committed changes (base...HEAD) and leave out uncommitted work."},
"title": stringProperty("Optional short caption shown above the diff."),
"replace": replaceProperty(),
}),
Annotations: map[string]any{"readOnlyHint": true, "openWorldHint": false},
},
{
Name: ToolNotify,
Title: "Notify the operator",
Description: "Send a notification to every Pipelines app the operator is signed in to (web, desktop, Android) and their phone; it opens this chat when tapped " +
"and is cleared on every device once they read it or open the chat. " +
"Pipelines already notifies when your reply ends and when you ask a question or request an approval, so do not notify for those. " +
"Use it only for something they should know mid-turn, or for background work that finishes after the turn (one notify in a turn replaces that turn's end-of-reply notification). " +
"Limited to 5 per minute per chat. Returns whether delivery was accepted.",
InputSchema: objectSchema([]string{"title", "message"}, map[string]any{
"title": stringProperty("Short notification title (one line)."),
"message": stringProperty("Notification text (one or two sentences)."),
"priority": map[string]any{"type": "string", "enum": []string{"low", "default", "high"}, "description": "Optional priority; default is default."},
}),
Annotations: map[string]any{"readOnlyHint": false, "destructiveHint": false, "openWorldHint": true},
},
{
Name: ToolShowRun,
Title: "Show a pipeline run in the chat",
Description: "Show the operator a live card for a Pipelines run: its pipeline, title, status, current stage and duration, " +
"kept current as the run progresses; tapping it opens the run. Use it after starting a run, or when the operator asks about one. " +
"The result names the item's id for replace.",
InputSchema: objectSchema([]string{"run_id"}, map[string]any{
"run_id": map[string]any{"type": "integer", "description": "The run's numeric id (as in `pipelines status <id>` or pipelines/run-<id>)."},
"title": stringProperty("Optional short caption shown above the run."),
"replace": replaceProperty(),
}),
Annotations: map[string]any{"readOnlyHint": true, "openWorldHint": false},
},
{
Name: ToolScheduleFollowup,
Title: "Schedule a follow-up in this chat",
Description: "Queue a message to yourself in this chat, delivered as a new prompt later: at a time (at, an RFC 3339 time, or after_minutes, " +
"between 1 minute and 7 days from now), or when a pipeline run reaches a state (run_id with on: finished when it ends, " +
"attention when it waits on the operator's decision or ends, whichever is first; delivered after 7 days at the latest). " +
"The operator sees it in the chat as a scheduled message from the agent and can remove it. At most 3 follow-ups can be pending per chat. " +
"It is delivered when the chat is free, so do not wait for it in the current turn. " +
"The result names the follow-up's id (for cancel_followup) and lists the chat's pending follow-ups.",
InputSchema: objectSchema([]string{"message"}, map[string]any{
"message": stringProperty("What the follow-up prompt should say: enough for you to know what to do then."),
"at": stringProperty("When to deliver it, as an RFC 3339 time such as 2026-05-01T09:30:00Z. Give this, after_minutes, or run_id."),
"after_minutes": map[string]any{"type": "integer", "description": "Minutes from now to deliver it (1-10080). Give this, at, or run_id."},
"run_id": map[string]any{"type": "integer", "description": "Deliver it when this pipeline run reaches on, instead of at a time."},
"on": map[string]any{"type": "string", "enum": []string{FollowupOnFinished, FollowupOnAttention},
"description": "With run_id: finished (the run ended: succeeded, failed, canceled or interrupted) or attention (it waits on a human decision, or ended). Default finished."},
}),
Annotations: map[string]any{"readOnlyHint": false, "destructiveHint": false, "openWorldHint": false},
},
{
Name: ToolCancelFollowup,
Title: "Cancel a follow-up in this chat",
Description: "Remove a follow-up this chat scheduled with schedule_followup and that has not been delivered yet. " +
"The result lists the follow-ups still pending.",
InputSchema: objectSchema([]string{"id"}, map[string]any{
"id": stringProperty("The follow-up's id, from the schedule_followup result."),
}),
Annotations: map[string]any{"readOnlyHint": false, "destructiveHint": false, "openWorldHint": false},
},
}
}