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)}},