From 5ebceee2dac944f19215ffcb324e4e03062bcf07 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 05:19:58 +0800 Subject: [PATCH] usage: the tool legend keeps each spelling's own kind (#2969) Follow-up to ggbdpq's b2a8b74c7 (the tool list grouped case-blind). That change put every spelling's calls in the legend under the kind of the spelling seen first, so where two spellings have different kinds ("task" is Other, "Task" is Task) the Categories legend changed with the order sessions were read in, and no longer matched the weeks (pd.tools), which count each spelling under its own kind. The legend now counts each call under ToolCategory of the name it was called by, as before b2a8b74c7; only the Top rows merge. The tie-break comment said "the shorter name", where the code takes the first in byte order. TestToolUseMergesSpellings gains "the legend keeps each spelling's own kind" ("task" 3 then "Task" 5: legend Task 5, Other 3). Broken by hand: with b2a8b74c7's stats.go it is red ("categories [{Name:Other Calls:8 Sessions:2}]"), green with this. Run at the pushed head on mote: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch. --- internal/sessions/stats.go | 17 ++++++++++------- internal/sessions/stats_tools_test.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/sessions/stats.go b/internal/sessions/stats.go index 1a0b41103..d67a4127d 100644 --- a/internal/sessions/stats.go +++ b/internal/sessions/stats.go @@ -836,7 +836,7 @@ func toolUse(in []*Summary, first time.Time, n int) ToolUse { key := strings.ToLower(name) // one tool apiece, its spellings together t := tools[key] if t == nil { - t = &ToolStat{Name: name, Category: ToolCategory(name)} + t = &ToolStat{Name: name} tools[key] = t } t.Calls += c @@ -846,16 +846,19 @@ func toolUse(in []*Summary, first time.Time, n int) ToolUse { } said[name] += c if best := shown[key]; best == "" || said[name] > said[best] || (said[name] == said[best] && name < best) { - shown[key] = name // its most called spelling, the shorter name on a tie + shown[key] = name // its most called spelling, the first in byte order on a tie } - cat := cats[t.Category] + // the legend counts each spelling under its own category, as + // the weeks do (pd.tools): "task" and "Task" are two there + k := ToolCategory(name) + cat := cats[k] if cat == nil { - cat = &ToolStat{Name: t.Category} - cats[t.Category] = cat + cat = &ToolStat{Name: k} + cats[k] = cat } cat.Calls += c - if !seen[t.Category] { - seen[t.Category] = true + if !seen[k] { + seen[k] = true cat.Sessions++ } } diff --git a/internal/sessions/stats_tools_test.go b/internal/sessions/stats_tools_test.go index f788d4b8b..f6bfc94a5 100644 --- a/internal/sessions/stats_tools_test.go +++ b/internal/sessions/stats_tools_test.go @@ -152,6 +152,20 @@ func TestToolUseMergesSpellings(t *testing.T) { calls: 135, sess: 2, }, + { + // the legend counts each spelling under its own kind, as the + // weeks do, whichever spelling came first: "task" is Other, + // "Task" is Task + name: "the legend keeps each spelling's own kind", + in: []Summary{ + {ToolCalls: 3, tools: countsOf(map[string]int{"task": 3}, nil)}, + {ToolCalls: 5, tools: countsOf(map[string]int{"Task": 5}, nil)}, + }, + top: []ToolStat{{Name: "Task", Category: "Task", Calls: 8, Sessions: 2}}, + cats: []ToolStat{{Name: "Task", Calls: 5, Sessions: 1}, {Name: "Other", Calls: 3, Sessions: 1}}, + calls: 8, + sess: 2, + }, { name: "tools that only share a kind stay apart", in: []Summary{{ToolCalls: 12, tools: countsOf(map[string]int{"mcp__github__create_issue": 5, "mcp__github__list_issues": 7}, nil)}},