Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
sessions: a summary's tools, skills and days are sorted slices, not maps
yetone3393e61d00d4
diff --git a/internal/sessions/alma_test.go b/internal/sessions/alma_test.goindex 8f178bf7b..99f173b98 100644--- a/internal/sessions/alma_test.go+++ b/internal/sessions/alma_test.go@@ -200,11 +200,11 @@ func TestAlmaSessions(t *testing.T) {t.Errorf("chat A stats: prompts %d replies %d tools %d", sum.Prompts, sum.Replies, sum.ToolCalls)}for _, tool := range []string{"Bash", "Skill", "Task", "mcp_search", "Read"} {- if sum.tools[tool] != 1 {- t.Errorf("tool %s called %d times, want 1 (%v)", tool, sum.tools[tool], sum.tools)+ if sum.tools.of(tool) != 1 {+ t.Errorf("tool %s called %d times, want 1 (%v)", tool, sum.tools.of(tool), sum.tools)}}- if sum.skills["image-gen"] != 1 {+ if sum.skills.of("image-gen") != 1 {t.Errorf("skills %v", sum.skills)}diff --git a/internal/sessions/external.go b/internal/sessions/external.goindex 4d6f8cbc2..3b79137ec 100644--- a/internal/sessions/external.go+++ b/internal/sessions/external.go@@ -110,11 +110,10 @@ func MergeExternalStats(st Stats, days []ExternalDayUsage, external []ExternalSefor j := range s.Days {s.Days[j] += shift}- pd := map[int]*summaryDay{}- for d, v := range s.perDay {- pd[d+shift] = v+ s.perDay = slices.Clone(s.perDay)+ for j := range s.perDay {+ s.perDay[j].day += shift}- s.perDay = pd}}byDate := map[string]int{}@@ -151,7 +150,8 @@ func MergeExternalStats(st Stats, days []ExternalDayUsage, external []ExternalSeif e.ID == "" || e.Agent == "" {continue}- s := Summary{Key: e.Agent + ":" + e.ID, Agent: e.Agent, ID: e.ID, Title: cmp.Or(names[e.Agent+"|"+e.ID], e.Title), Gateway: true, Last: e.Last, Tokens: e.Tokens, Cost: e.Cost, Priced: true, Models: []string{}, Days: []int{}, perDay: map[int]*summaryDay{}}+ s := Summary{Key: e.Agent + ":" + e.ID, Agent: e.Agent, ID: e.ID, Title: cmp.Or(names[e.Agent+"|"+e.ID], e.Title), Gateway: true, Last: e.Last, Tokens: e.Tokens, Cost: e.Cost, Priced: true, Models: []string{}, Days: []int{}}+ perDay := map[int]*summaryDay{}for _, u := range e.Daily {day, err := time.ParseInLocation(time.DateOnly, u.Date, time.Local)if err != nil {@@ -161,15 +161,18 @@ func MergeExternalStats(st Stats, days []ExternalDayUsage, external []ExternalSeif first.IsZero() || u.Date < st.From || u.Date > st.To {continue}- pd := s.perDay[d]+ pd := perDay[d]if pd == nil {- pd = &summaryDay{}- s.perDay[d] = pd+ pd = &summaryDay{day: d}+ perDay[d] = pds.Days = append(s.Days, d)}pd.output += u.Output}sort.Ints(s.Days)+ for _, d := range s.Days {+ s.perDay = append(s.perDay, *perDay[d])+ }for _, m := range e.Models {s.Models = append(s.Models, m.Model)s.Priced = s.Priced && m.Priceddiff --git a/internal/sessions/external_test.go b/internal/sessions/external_test.goindex 2654427a3..aed52357b 100644--- a/internal/sessions/external_test.go+++ b/internal/sessions/external_test.go@@ -6,7 +6,7 @@ import ()func TestGatewayStatsRebaseNativeCalendar(t *testing.T) {- native := Stats{From: "2026-10-06", To: "2026-10-07", Sessions: []Summary{{Agent: "claude", ID: "native", Days: []int{0}, perDay: map[int]*summaryDay{0: {output: 4}}}}}+ native := Stats{From: "2026-10-06", To: "2026-10-07", Sessions: []Summary{{Agent: "claude", ID: "native", Days: []int{0}, perDay: []summaryDay{{day: 0, output: 4}}}}}merged := MergeExternalStats(native, []ExternalDayUsage{{Date: "2026-10-04", Agent: "opencode"}}, nil)view := merged.Overview("claude", "", "", 8)if !reflect.DeepEqual(view.Days, []int{0, 0, 1, 0}) || !reflect.DeepEqual(view.Output, []int{0, 0, 4, 0}) {diff --git a/internal/sessions/stats.go b/internal/sessions/stats.goindex f741c9f57..f944e8fd0 100644--- a/internal/sessions/stats.go+++ b/internal/sessions/stats.go@@ -60,16 +60,48 @@ type Summary struct {Replies int `json:"replies"`ToolCalls int `json:"tool_calls"`- tools map[string]int // calls by tool- skills map[string]int // calls by skill- skillLast map[string]string // the last date each skill was called- perDay map[int]*summaryDay // by day after From+ // slices and not maps: each range statsFor keeps holds them for every+ // session, and a map of one or two names is a few hundred bytes+ tools counts // calls by tool+ skills counts // calls by skill, with the last date of each+ perDay []summaryDay // by day after From, in order}// summaryDay is a session's day, for the overview's calendar and trends.type summaryDay struct {+ day int // after Frommessages, output int- tools map[string]int // calls by tool category+ tools counts // calls by tool category+}++// counts are calls by name, in the names' order.+type counts []nameCount++type nameCount struct {+ name string+ n int+ last string // a skill's: the last date it was called+}++// of is name's calls.+func (c counts) of(name string) int {+ if i, ok := slices.BinarySearchFunc(c, name, func(c nameCount, name string) int { return strings.Compare(c.name, name) }); ok {+ return c[i].n+ }+ return 0+}++// countsOf is m in the names' order, with last's date for each when given.+func countsOf(m map[string]int, last map[string]string) counts {+ if len(m) == 0 {+ return nil+ }+ out := make(counts, 0, len(m))+ for name, n := range m {+ out = append(out, nameCount{name: name, n: n, last: last[name]})+ }+ slices.SortFunc(out, func(a, b nameCount) int { return strings.Compare(a.name, b.name) })+ return out}// Day is one local date's usage, cut fine enough for the page to filter@@ -193,6 +225,10 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats {act := map[ak]*act0{}dates := map[string]bool{}// each session's share: its files' models and dates in range+ type dayShare struct {+ messages, output int+ tools map[string]int+ }type share struct {models map[string]Tokensactive int64@@ -200,7 +236,7 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats {prompts, replies inttools, skills map[string]intskillLast map[string]string- perDate map[string]*summaryDay+ perDate map[string]*dayShare}shares := map[string]*share{}for _, f := range want {@@ -247,12 +283,12 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats {sh := shares[f.key]if sh == nil {sh = &share{models: map[string]Tokens{}, dates: map[string]bool{}, tools: map[string]int{},- skills: map[string]int{}, skillLast: map[string]string{}, perDate: map[string]*summaryDay{}}+ skills: map[string]int{}, skillLast: map[string]string{}, perDate: map[string]*dayShare{}}shares[f.key] = sh}pd := sh.perDate[date]if pd == nil {- pd = &summaryDay{tools: map[string]int{}}+ pd = &dayShare{tools: map[string]int{}}sh.perDate[date] = pd}for model, t := range d.Models {@@ -358,16 +394,17 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats {sum := Summary{Key: key, Agent: s.Agent, ID: s.ID, Cwd: cmp.Or(folder[key], s.Cwd), Title: clip(s.Title, titleKept),Nickname: s.Nickname,Last: s.Last, Role: s.Role, ParentSession: s.ParentSession, RootSession: s.RootSession, Priced: true, Active: sh.active / 1000, Models: []string{}, Days: []int{},- Prompts: sh.prompts, Replies: sh.replies, tools: sh.tools, skills: sh.skills, skillLast: sh.skillLast,- perDay: map[int]*summaryDay{}}+ Prompts: sh.prompts, Replies: sh.replies, tools: countsOf(sh.tools, nil), skills: countsOf(sh.skills, sh.skillLast)}for _, n := range sh.tools {sum.ToolCalls += n}+ sum.perDay = make([]summaryDay, 0, len(sh.perDate))for date, pd := range sh.perDate {if t, err := time.ParseInLocation(time.DateOnly, date, time.Local); err == nil {- sum.perDay[int(math.Round(t.Sub(first).Hours()/24))] = pd+ sum.perDay = append(sum.perDay, summaryDay{day: int(math.Round(t.Sub(first).Hours() / 24)), messages: pd.messages, output: pd.output, tools: countsOf(pd.tools, nil)})}}+ slices.SortFunc(sum.perDay, func(a, b summaryDay) int { return cmp.Compare(a.day, b.day) })for model, t := range sh.models {sum.Tokens.add(t)sum.Models = append(sum.Models, model)@@ -522,8 +559,8 @@ func (st Stats) Overview(agent, model, cwd string, n int) Overview {out.Days[d]++}}- for d, pd := range s.perDay {- if d >= 0 && d < len(out.Days) {+ for _, pd := range s.perDay {+ if d := pd.day; d >= 0 && d < len(out.Days) {out.Messages[d] += pd.messagesout.Output[d] += pd.output}@@ -603,7 +640,8 @@ func toolUse(in []Summary, first time.Time, n int) ToolUse {out.Sessions++out.Calls += s.ToolCallsseen := map[string]bool{}- for name, c := range s.tools {+ for _, tc := range s.tools {+ name, c := tc.name, tc.nt := tools[name]if t == nil {t = &ToolStat{Name: name, Category: ToolCategory(name)}@@ -625,16 +663,16 @@ func toolUse(in []Summary, first time.Time, n int) ToolUse {if first.IsZero() {continue}- for d, pd := range s.perDay {- day := first.AddDate(0, 0, d)+ for _, pd := range s.perDay {+ day := first.AddDate(0, 0, pd.day)mon := day.AddDate(0, 0, -(int(day.Weekday())+6)%7).Format(time.DateOnly)w := weeks[mon]if w == nil {w = map[string]int{}weeks[mon] = w}- for cat, c := range pd.tools {- w[cat] += c+ for _, c := range pd.tools {+ w[c.name] += c.n}}}@@ -661,7 +699,8 @@ func skillUse(in []Summary, n int) SkillUse {skills := map[string]*Skill{}projects := map[string]map[string]int{}for _, s := range in {- for name, c := range s.skills {+ for _, sc := range s.skills {+ name, c := sc.name, sc.nk := skills[name]if k == nil {k = &Skill{Name: name, Agents: map[string]int{}, Projects: []ToolStat{}}@@ -671,7 +710,7 @@ func skillUse(in []Summary, n int) SkillUse {k.Calls += ck.Sessions++k.Agents[s.Agent] += c- k.Last = max(k.Last, s.skillLast[name])+ k.Last = max(k.Last, sc.last)projects[name][s.Cwd] += cout.Calls += c}diff --git a/internal/sessions/stats_pi_test.go b/internal/sessions/stats_pi_test.goindex 758469a95..e5643e14e 100644--- a/internal/sessions/stats_pi_test.go+++ b/internal/sessions/stats_pi_test.go@@ -58,10 +58,10 @@ func TestPiToolsAndMessages(t *testing.T) {if p.Prompts != 2 || p.Replies != 4 || p.ToolCalls != 7 {t.Fatalf("pi: %d prompts, %d replies, %d calls (%v)", p.Prompts, p.Replies, p.ToolCalls, p.tools)}- if p.tools["bash"] != 1 || p.tools["read"] != 2 || p.tools["codemode"] != 1 || p.tools["mcp__opencli_mcp__open"] != 1 || p.tools["edit"] != 1 {+ if p.tools.of("bash") != 1 || p.tools.of("read") != 2 || p.tools.of("codemode") != 1 || p.tools.of("mcp__opencli_mcp__open") != 1 || p.tools.of("edit") != 1 {t.Fatalf("pi tools %v", p.tools)}- if p.skills["pdf"] != 1 || p.skills["review"] != 1 || len(p.skills) != 2 {+ if p.skills.of("pdf") != 1 || p.skills.of("review") != 1 || len(p.skills) != 2 {t.Fatalf("pi skills %v", p.skills)}// the fork's own prompt and reply; what it copied is the first'sdiff --git a/internal/sessions/stats_tools_test.go b/internal/sessions/stats_tools_test.goindex 2506d9c38..fd92d3358 100644--- a/internal/sessions/stats_tools_test.go+++ b/internal/sessions/stats_tools_test.go@@ -66,10 +66,10 @@ func TestStatsToolsAndSkills(t *testing.T) {if cc.Prompts != 2 || cc.Replies != 2 || cc.ToolCalls != 5 {t.Fatalf("claude: %d prompts, %d replies, %d calls (%v)", cc.Prompts, cc.Replies, cc.ToolCalls, cc.tools)}- if cc.tools["Bash"] != 1 || cc.tools["Grep"] != 1 || cc.tools["mcp__slack__send"] != 1 || cc.skills["artifact-design"] != 1 {+ if cc.tools.of("Bash") != 1 || cc.tools.of("Grep") != 1 || cc.tools.of("mcp__slack__send") != 1 || cc.skills.of("artifact-design") != 1 {t.Fatalf("claude tools %v skills %v", cc.tools, cc.skills)}- if cxs.Prompts != 2 || cxs.Replies != 1 || cxs.ToolCalls != 2 || cxs.tools["exec_command"] != 1 || cxs.tools["apply_patch"] != 1 {+ if cxs.Prompts != 2 || cxs.Replies != 1 || cxs.ToolCalls != 2 || cxs.tools.of("exec_command") != 1 || cxs.tools.of("apply_patch") != 1 {t.Fatalf("codex: %+v %v", cxs, cxs.tools)}