fix(messaging): render a tool call as one line with its own icon
A tool call rendered as a label line plus a ```text fence. Telegram draws a fenced block as a full code widget (language header bar, copy button, panel), and the block parser inserts a spacer paragraph before every block, so one call cost four rendered elements. Three calls filled the screen to show three word counts. Every toolPreview path already summarises to a single line, so the fence was never wrapping more than one. Drop it and put the preview on the header line. Tool lines now join with a hard break rather than a bare newline: a soft break would space-join them into one run-on paragraph, and a blank line would put the spacer back. Three calls are now three consecutive blocks. Two hardcoded values go with it. The status word is printed only when the outcome is not success, since every line otherwise read "done" and distinguished nothing. The icon is no longer a literal in the renderer: each builtin declares its own on tools.Tool (not on Schema, which is the model's contract), the provider carries it into ToolEntry, and the turn snapshots the registry's icons alongside its tool set. A tool that declares none renders without one rather than borrowing a generic wrench. Carries a dependency upgrade (go.mod, go.sum, tools/go.mod, tools/go.sum).
This commit is contained in:
22 files changed
+340
-49
No files matched your search
@@ -74,6 +74,7 @@ func NewEditTool(cwd string, mq *MutationQueue, rt *ReadTracker) Tool {
|
||||
return Tool{
|
||||
Schema: editSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "✏️",
|
||||
Execute: makeEditExecutor(cwd, mq, rt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ func NewFindTool(cwd string) Tool {
|
||||
return Tool{
|
||||
Schema: findSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "📁",
|
||||
Execute: makeFindExecutor(cwd),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@ func NewGrepTool(cwd string, indexes ...GrepIndex) Tool {
|
||||
return Tool{
|
||||
Schema: grepSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "🔍",
|
||||
Execute: makeGrepExecutor(cwd, workspaceIndex),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,6 +209,7 @@ func NewReadTool(cwd string, rt *ReadTracker) Tool {
|
||||
return Tool{
|
||||
Schema: readSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "📄",
|
||||
Execute: makeReadExecutor(cwd, rt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ type Tool struct {
|
||||
Schema Schema
|
||||
Execute Executor
|
||||
Source string // "builtin", "extension:<name>"
|
||||
// Emoji is the icon chat surfaces show for this tool. It is deliberately
|
||||
// not part of Schema: Schema is serialised to the model as the tool's
|
||||
// contract, and an icon is presentation. Empty means no icon.
|
||||
Emoji string
|
||||
}
|
||||
|
||||
// Registry holds all registered tools and provides thread-safe access.
|
||||
|
||||
@@ -74,6 +74,7 @@ func NewShellTool(cwd string, mq *MutationQueue) Tool {
|
||||
return Tool{
|
||||
Schema: shellSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "💻",
|
||||
Execute: makeShellExecutor(cwd, mq),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ func NewWriteTool(cwd string, mq *MutationQueue, rt *ReadTracker) Tool {
|
||||
return Tool{
|
||||
Schema: writeSchema,
|
||||
Source: "builtin",
|
||||
Emoji: "📝",
|
||||
Execute: makeWriteExecutor(cwd, mq, rt),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ func toEntry(tool toolsbuiltin.Tool) (tools.ToolEntry, error) {
|
||||
Toolset: toolset,
|
||||
Schema: schema,
|
||||
Classification: classify(tool.Schema.Name),
|
||||
Emoji: tool.Emoji,
|
||||
Handler: handlerFor(tool),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -305,3 +305,28 @@ func TestGrepConsultsSuppliedWorkspaceIndex(t *testing.T) {
|
||||
t.Errorf("index asked for pattern %q, want the caller's pattern %q", pattern, "Target")
|
||||
}
|
||||
}
|
||||
|
||||
// TestWorkspaceToolsCarryTheirOwnIcon pins that each builtin declares an icon
|
||||
// and that the conversion carries it. A chat surface renders what the tool
|
||||
// registered, so an icon missing here is an icon missing on screen.
|
||||
func TestWorkspaceToolsCarryTheirOwnIcon(t *testing.T) {
|
||||
p := startedProvider(t, t.TempDir())
|
||||
entries, err := p.Discover(t.Context())
|
||||
if err != nil {
|
||||
t.Fatalf("Tools: %v", err)
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
t.Fatal("no workspace tools registered")
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
for _, entry := range entries {
|
||||
if entry.Emoji == "" {
|
||||
t.Errorf("tool %q registered no icon", entry.Name)
|
||||
continue
|
||||
}
|
||||
seen[entry.Emoji] = true
|
||||
}
|
||||
if len(seen) < 2 {
|
||||
t.Errorf("icons = %v, want tools to be distinguishable by icon", seen)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user