Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
sessions: the overview's stats and their native sessions come of one pass over the files (#2776)
yetone81029fc63c7f
diff --git a/internal/gui/sessions.go b/internal/gui/sessions.goindex fe1b46e62..17ce06eca 100644--- a/internal/gui/sessions.go+++ b/internal/gui/sessions.go@@ -452,11 +452,7 @@ func statsFor(days int) sessions.Stats {}func combinedSessionStats(days int) sessions.Stats {- st := sessions.StatsFor(days)- nativeKeys := map[string]bool{}- for _, s := range sessions.List(sessions.All) {- nativeKeys[s.Agent+"|"+s.ID] = true- }+ st, nativeKeys := sessions.StatsAndNative(days)var since time.Timeif days > 0 && st.From != "" {since, _ = time.ParseInLocation(time.DateOnly, st.From, time.Local)diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.goindex e59b449c5..dd96027b5 100644--- a/internal/sessions/sessions.go+++ b/internal/sessions/sessions.go@@ -469,7 +469,14 @@ func ccFiles(agent, dir string) []file {}// allFiles are every agent's session files.+// filesHook, when a test sets it, runs on each pass over every agent's+// files.+var filesHook func()+func allFiles() []file {+ if filesHook != nil {+ filesHook()+ }var out []filefor _, fs := range [][]file{callFiles(), openCodeFiles(), piFiles(),wslFiles("pi", "omp", "kimi"), zcodeFiles(), dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")),diff --git a/internal/sessions/stats.go b/internal/sessions/stats.goindex c4aa927fd..c8035dc3e 100644--- a/internal/sessions/stats.go+++ b/internal/sessions/stats.go@@ -108,7 +108,19 @@ func StatsFor(days int) Stats {// StatsAt is StatsFor as if it were now.func StatsAt(days int, now time.Time) Stats { return statsAt(days, now) }-func statsAt(days int, now time.Time) Stats {+// StatsAndNative is StatsFor, and the agent|id of every session List would+// list, with no limit: what tells a gateway session the agent keeps too+// from one only magpie saw. Both come of one pass over the files, as the+// overview asks for both on every poll (#2776).+func StatsAndNative(days int) (Stats, map[string]bool) {+ native := map[string]bool{}+ return statsIn(days, time.Now(), native), native+}++func statsAt(days int, now time.Time) Stats { return statsIn(days, now, nil) }++// statsIn is statsAt, filling native as StatsAndNative says when not nil.+func statsIn(days int, now time.Time, native map[string]bool) Stats {now = now.In(time.Local)today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)var since time.Time@@ -131,6 +143,19 @@ func statsAt(days int, now time.Time) Stats {refresh(files, files)identities := codexIdentitySnapshot(files)taskTitles := codexSubagentTaskTitles(files)+ if native != nil {+ groups := map[string][]file{}+ for _, f := range files {+ groups[f.key] = append(groups[f.key], f)+ }+ price := pricer()+ for _, fs := range groups {+ // as List: a session nothing was said in is not listed+ if s, ok := assemble(fs, price); ok {+ native[s.Agent+"|"+s.ID] = true+ }+ }+ }var want []filefor _, f := range files {if !f.mod.Before(since) {diff --git a/internal/sessions/stats_native_test.go b/internal/sessions/stats_native_test.gonew file mode 100644index 000000000..66b988563--- /dev/null+++ b/internal/sessions/stats_native_test.go@@ -0,0 +1,32 @@+package sessions++import "testing"++// The overview's stats and the sessions that tell its gateway sessions+// apart come of one pass over every agent's files (#2776): it took a second+// pass, through List(All), on every refresh. The keys are List's.+func TestStatsAndNativeOnePass(t *testing.T) {+ setup(t)+ want := map[string]bool{}+ for _, s := range List(All) {+ want[s.Agent+"|"+s.ID] = true+ }+ passes := 0+ filesHook = func() { passes++ }+ t.Cleanup(func() { filesHook = nil })+ st, native := StatsAndNative(0)+ if passes != 1 {+ t.Fatalf("%d passes over the files", passes)+ }+ if len(st.Sessions) == 0 {+ t.Fatalf("no stats: %+v", st)+ }+ if len(native) != len(want) || len(want) < 2 {+ t.Fatalf("native %v, List's %v", native, want)+ }+ for k := range want {+ if !native[k] {+ t.Fatalf("native %v, List's %v", native, want)+ }+ }+}