@koinzhang/paseo-plugin-activity 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/README.md +18 -11
  3. package/client/activity-heatmap.tsx +115 -74
  4. package/client/agent-creations.tsx +100 -90
  5. package/client/attention-pill.tsx +17 -6
  6. package/client/attention-popover.tsx +19 -23
  7. package/client/design-tokens.test.ts +39 -0
  8. package/client/design-tokens.ts +180 -0
  9. package/client/formatted-time.tsx +4 -4
  10. package/client/global-surface.tsx +243 -268
  11. package/client/header-button.ts +136 -0
  12. package/client/hourly-activity-timeline.tsx +153 -103
  13. package/client/panel-visibility.test.ts +25 -0
  14. package/client/panel-visibility.ts +45 -0
  15. package/client/panel.tsx +94 -111
  16. package/client/pill.tsx +1 -1
  17. package/client/provider-dropdown.tsx +134 -0
  18. package/client/provider-filter.test.ts +17 -13
  19. package/client/provider-filter.ts +5 -7
  20. package/client/rank-color.ts +3 -3
  21. package/client/ranking-bars.tsx +294 -0
  22. package/client/sidebar-item.tsx +15 -0
  23. package/client/ui.tsx +351 -0
  24. package/client/usage-popover.tsx +72 -137
  25. package/client/usage-stats.tsx +29 -11
  26. package/client/use-agent-turn-end.ts +2 -1
  27. package/client/use-app-language.ts +17 -0
  28. package/client/web.ts +73 -18
  29. package/client/workspace/agent-row.tsx +28 -28
  30. package/client/workspace/agents-section.tsx +42 -57
  31. package/client/workspace/constants.ts +8 -6
  32. package/client/workspace/display-menu.tsx +6 -5
  33. package/client/workspace/filters.test.ts +1 -1
  34. package/client/workspace/filters.ts +4 -2
  35. package/client/workspace/panel.tsx +96 -104
  36. package/client/workspace/rank-section.tsx +40 -65
  37. package/client/workspace/running-indicator.tsx +1 -1
  38. package/client/workspace/terminals-section.tsx +24 -12
  39. package/index.client.tsx +53 -31
  40. package/index.server.ts +55 -73
  41. package/package.json +3 -3
  42. package/paseo-plugin.json +2 -1
  43. package/server/agents.ts +20 -2
  44. package/server/background-sync.ts +34 -4
  45. package/server/handlers-query.test.ts +27 -1
  46. package/server/handlers.ts +75 -31
  47. package/server/host-types.ts +6 -6
  48. package/server/ingest.test.ts +8 -0
  49. package/server/messages.test.ts +96 -1
  50. package/server/prompt-dedupe.ts +52 -0
  51. package/server/rpc-cache.test.ts +74 -0
  52. package/server/rpc-cache.ts +48 -0
  53. package/server/store.test.ts +122 -0
  54. package/server/store.ts +313 -19
  55. package/server/ttl-cache.ts +3 -0
  56. package/server/turn-ingest.test.ts +180 -0
  57. package/server/turn-ingest.ts +71 -0
  58. package/shared/activity.test.ts +36 -0
  59. package/shared/activity.ts +37 -0
  60. package/shared/classify.test.ts +1 -10
  61. package/shared/classify.ts +3 -10
  62. package/shared/format.ts +10 -7
  63. package/shared/i18n.test.ts +34 -0
  64. package/shared/i18n.ts +363 -0
  65. package/shared/insights.test.ts +120 -81
  66. package/shared/insights.ts +125 -64
  67. package/shared/usage.test.ts +121 -0
  68. package/shared/usage.ts +191 -2
@@ -1,10 +1,8 @@
1
1
  import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
2
- import { Icon } from "@getpaseo/plugin/client/react-native";
2
+ import { Icon } from "@getpaseo/plugin/client/ui";
3
3
  import { keepPreviousData, useQuery } from "@tanstack/react-query";
4
4
  import { useEffect, useMemo, useState, type ReactNode } from "react";
5
5
  import {
6
- ActivityIndicator,
7
- Pressable,
8
6
  ScrollView,
9
7
  Text,
10
8
  View,
@@ -17,34 +15,40 @@ import {
17
15
  usageActivityByDayRpc,
18
16
  usageAgentCreationsRpc,
19
17
  usageAgentLifetimeRpc,
18
+ usageByProjectRpc,
20
19
  usageByProviderRpc,
20
+ OTHER_PROJECT_KEY,
21
21
  type ProviderUsageItem,
22
22
  } from "../shared/usage.ts";
23
23
  import { formatDisplayName } from "../shared/format.ts";
24
- import {
25
- ActivityHeatmap,
26
- computeStreaks,
27
- type HeatmapMode,
28
- } from "./activity-heatmap.tsx";
24
+ import { ActivityHeatmap } from "./activity-heatmap.tsx";
29
25
  import { AgentCreations } from "./agent-creations.tsx";
30
26
  import { HourlyActivityTimeline } from "./hourly-activity-timeline.tsx";
31
-
27
+ import { ProviderDropdown } from "./provider-dropdown.tsx";
28
+ import { RankingBars, type RankingEntry } from "./ranking-bars.tsx";
32
29
  import { UsageStats } from "./usage-stats.tsx";
33
- import { chartColorScheme, entityColor } from "./rank-color.ts";
30
+ import { chartColorScheme, entityColor, providerColor } from "./rank-color.ts";
34
31
  import { selectProviderOptions } from "./provider-filter.ts";
35
32
  import { useAppLanguage } from "./use-app-language.ts";
36
- import { buildActivityInsights, buildActivityKpi, ACTIVITY_LIST_LIMIT } from "../shared/insights.ts";
37
- import { fixedWindowFrom, rangeFrom, RANGE_OPTIONS, type RangeId } from "./range.ts";
33
+ import { buildActivityInsights, buildActivityKpi } from "../shared/insights.ts";
34
+ import { fixedWindowFrom } from "./range.ts";
38
35
  import { useRegisterOpenAgent } from "./open-agent.ts";
39
-
40
- /** Max rows for Activity insights and Most used skills / MCP. */
41
- const LIST_LIMIT = ACTIVITY_LIST_LIMIT;
42
-
43
- /** Fixed width of the creations histogram, independent of the range chips (050). */
36
+ import { CONTROL, ICON_SIZE, ROW_PADDING, TEXT, pageLayout, titleGap } from "./design-tokens.ts";
37
+ import { messagesFor, type Messages } from "../shared/i18n.ts";
38
+ import {
39
+ ErrorState,
40
+ IconButton,
41
+ InlineEmpty,
42
+ LoadingState,
43
+ PageEmpty,
44
+ SectionHeader,
45
+ } from "./ui.tsx";
46
+
47
+ /** Fixed width of the creations histogram (050). */
44
48
  const CREATIONS_WINDOW_DAYS = 30;
45
49
  const HOURLY_WINDOW_HOURS = 7 * 24;
46
50
 
47
- /** Zeroed provider row when the chip exists all-time but the time window has no rows. */
51
+ /** Zeroed provider row when a selected provider has no usage row. */
48
52
  function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem {
49
53
  return {
50
54
  provider,
@@ -71,31 +75,6 @@ function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem
71
75
 
72
76
 
73
77
 
74
- function TextTabs({
75
- options,
76
- value,
77
- onChange,
78
- styles,
79
- }: {
80
- options: ReadonlyArray<{ id: string; label: string }>;
81
- value: string;
82
- onChange: (id: string) => void;
83
- styles: { tabRow: ViewStyle; tab: TextStyle; tabActive: TextStyle };
84
- }): ReactNode {
85
- return (
86
- <View style={styles.tabRow}>
87
- {options.map((option) => {
88
- const active = option.id === value;
89
- return (
90
- <Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: active }} style={{ paddingVertical: 6 }} onPress={() => onChange(option.id)}>
91
- <Text style={active ? styles.tabActive : styles.tab}>{option.label}</Text>
92
- </Pressable>
93
- );
94
- })}
95
- </View>
96
- );
97
- }
98
-
99
78
  type RankKind = "skills" | "mcp" | "models";
100
79
 
101
80
  type RankItem = {
@@ -104,7 +83,7 @@ type RankItem = {
104
83
  count: number;
105
84
  kind: RankKind;
106
85
  server?: string;
107
- countLabel?: string;
86
+ unit?: "prompts";
108
87
  };
109
88
 
110
89
  const RANK_CYCLE: RankKind[] = ["skills", "mcp", "models"];
@@ -113,29 +92,10 @@ function nextRankKind(kind: RankKind): RankKind {
113
92
  return RANK_CYCLE[(RANK_CYCLE.indexOf(kind) + 1) % RANK_CYCLE.length] ?? "skills";
114
93
  }
115
94
 
116
- function rankTitle(kind: RankKind): string {
117
- if (kind === "skills") return "Most used skills";
118
- if (kind === "mcp") return "Most used MCP";
119
- return "Most used models";
120
- }
121
-
122
- function rankEmpty(kind: RankKind): string {
123
- if (kind === "skills") return "No skills yet";
124
- if (kind === "mcp") return "No MCP yet";
125
- return "No models yet";
126
- }
127
-
128
- function rankHeaderAction(kind: RankKind): {
129
- icon: "Sparkles" | "Plug" | "Bot";
130
- accessibilityLabel: string;
131
- } {
132
- if (kind === "skills") {
133
- return { icon: "Plug", accessibilityLabel: "Show most used MCP" };
134
- }
135
- if (kind === "mcp") {
136
- return { icon: "Bot", accessibilityLabel: "Show most used models" };
137
- }
138
- return { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
95
+ function rankShowIcon(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
96
+ if (kind === "skills") return "Plug";
97
+ if (kind === "mcp") return "Bot";
98
+ return "Sparkles";
139
99
  }
140
100
 
141
101
  function rankIconName(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
@@ -144,72 +104,93 @@ function rankIconName(kind: RankKind): "Sparkles" | "Plug" | "Bot" {
144
104
  return "Bot";
145
105
  }
146
106
 
107
+ const ROW_GAP = 2;
108
+
147
109
  function RankList({
148
110
  title,
149
111
  items,
150
112
  empty,
151
113
  styles,
152
114
  colors,
115
+ compact,
116
+ units,
117
+ visibleRows,
153
118
  headerAction,
154
119
  }: {
155
120
  title: string;
156
121
  items: RankItem[];
157
122
  empty: string;
158
123
  styles: {
159
- block: ViewStyle;
160
- blockTitle: TextStyle;
161
- titleRow: ViewStyle;
162
- titleAction: ViewStyle;
124
+ columnHeader: ViewStyle;
163
125
  rankRow: ViewStyle;
164
126
  rankName: TextStyle;
165
127
  rankMeta: TextStyle;
166
- emptyHint: TextStyle;
167
128
  };
168
- colors: { accent: string; foregroundMuted: string; surface0: string };
129
+ colors: { accent: string; foreground: string; foregroundMuted: string; surface0: string };
130
+ compact: boolean;
131
+ units: Messages["units"];
132
+ /** Rows shown before the list scrolls (matches the Insights column). */
133
+ visibleRows: number;
169
134
  headerAction?: {
170
135
  icon: "Sparkles" | "Plug" | "Bot";
171
136
  accessibilityLabel: string;
172
137
  onPress: () => void;
173
138
  };
174
139
  }): ReactNode {
140
+ const [rowHeight, setRowHeight] = useState(0);
175
141
  return (
176
- <View style={styles.block}>
177
- <View style={styles.titleRow}>
178
- <Text style={styles.blockTitle}>{title}</Text>
179
- {headerAction ? (
180
- <Pressable
181
- accessibilityRole="button"
182
- accessibilityLabel={headerAction.accessibilityLabel}
183
- hitSlop={8}
184
- onPress={headerAction.onPress}
185
- style={styles.titleAction}
186
- >
187
- <Icon name={headerAction.icon} size={16} color={colors.foregroundMuted} />
188
- </Pressable>
189
- ) : null}
142
+ <View style={{ gap: ROW_GAP }}>
143
+ <View style={styles.columnHeader}>
144
+ <SectionHeader title={title} colors={colors} compact={compact}>
145
+ {headerAction ? (
146
+ <IconButton
147
+ icon={headerAction.icon}
148
+ label={headerAction.accessibilityLabel}
149
+ onPress={headerAction.onPress}
150
+ color={colors.foregroundMuted}
151
+ />
152
+ ) : null}
153
+ </SectionHeader>
190
154
  </View>
191
155
  {items.length === 0 ? (
192
- <Text style={styles.emptyHint}>{empty}</Text>
156
+ <InlineEmpty text={empty} color={colors.foregroundMuted} />
193
157
  ) : (
194
- items.map((item) => (
195
- <View key={item.key} style={styles.rankRow}>
196
- <Icon
197
- name={rankIconName(item.kind)}
198
- size={14}
199
- color={
200
- item.kind === "mcp"
201
- ? entityColor(item.server ?? "", chartColorScheme(colors.surface0))
202
- : colors.accent
203
- }
204
- />
205
- <Text style={styles.rankName} numberOfLines={1}>
206
- {item.label}
207
- </Text>
208
- <Text style={styles.rankMeta}>
209
- {item.count} {item.countLabel ?? "calls"}
210
- </Text>
211
- </View>
212
- ))
158
+ <ScrollView
159
+ key={items[0]?.kind}
160
+ style={{
161
+ maxHeight:
162
+ items.length > visibleRows && rowHeight > 0
163
+ ? visibleRows * rowHeight + (visibleRows - 1) * ROW_GAP
164
+ : undefined,
165
+ }}
166
+ contentContainerStyle={{ gap: ROW_GAP }}
167
+ showsVerticalScrollIndicator={false}
168
+ nestedScrollEnabled
169
+ >
170
+ {items.map((item, index) => (
171
+ <View
172
+ key={item.key}
173
+ style={styles.rankRow}
174
+ onLayout={index === 0 ? (event) => setRowHeight(event.nativeEvent.layout.height) : undefined}
175
+ >
176
+ <Icon
177
+ name={rankIconName(item.kind)}
178
+ size={ICON_SIZE.inline}
179
+ color={
180
+ item.kind === "mcp"
181
+ ? entityColor(item.server ?? "", chartColorScheme(colors.surface0))
182
+ : colors.accent
183
+ }
184
+ />
185
+ <Text style={styles.rankName} numberOfLines={1}>
186
+ {item.label}
187
+ </Text>
188
+ <Text style={styles.rankMeta}>
189
+ {item.unit === "prompts" ? units.prompts(item.count) : units.calls(item.count)}
190
+ </Text>
191
+ </View>
192
+ ))}
193
+ </ScrollView>
213
194
  )}
214
195
  </View>
215
196
  );
@@ -217,51 +198,54 @@ function RankList({
217
198
 
218
199
  export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceProps) {
219
200
  useRegisterOpenAgent(navigation?.openAgent);
220
- const [range, setRange] = useState<RangeId>("all");
221
201
  const [providerFilter, setProviderFilter] = useState<string>("all");
222
- const [heatmapMode, setHeatmapMode] = useState<HeatmapMode>("daily");
223
202
  const [rankKind, setRankKind] = useState<RankKind>("skills");
224
203
  const locale = useAppLanguage();
225
- // Recompute on each render so today / rolling windows refresh after midnight (poll-driven).
226
- const from = rangeFrom(range);
204
+ const m = messagesFor(locale);
227
205
 
228
- const padding = layout.compact ? 16 : 20;
206
+ const page = pageLayout("surface", layout.compact);
229
207
  const byProvider = useRpc(usageByProviderRpc);
208
+ const byProject = useRpc(usageByProjectRpc);
230
209
  const activityByDay = useRpc(usageActivityByDayRpc);
231
210
  const activityByHour = useRpc(usageActivityByHourRpc);
232
211
  const agentLifetime = useRpc(usageAgentLifetimeRpc);
233
212
  const agentCreations = useRpc(usageAgentCreationsRpc);
234
213
 
235
- const filter = from ? { from } : {};
236
-
237
- /** All-time providers for filter chips (agents / skills / messages / …). */
238
- const catalogQuery = useQuery({
214
+ // The page is all-time (069): one by-provider query feeds the dropdown, KPI,
215
+ // lists and the provider ranking.
216
+ const query = useQuery({
239
217
  refetchInterval: 15_000,
240
218
  retry: false,
241
219
  queryKey: ["activity", "by-provider", "all"],
242
220
  queryFn: () => byProvider({}),
243
221
  });
244
222
 
245
- const query = useQuery({
223
+ const currentWindowStart = fixedWindowFrom(7);
224
+ const previousWindowStart = fixedWindowFrom(14);
225
+ // The RPC's `to` is inclusive; end the previous window just before this one.
226
+ const previousWindowEnd = new Date(Date.parse(currentWindowStart) - 1).toISOString();
227
+ const comparisonQuery = useQuery({
246
228
  refetchInterval: 15_000,
247
229
  retry: false,
248
- // Shares cache with catalogQuery when range === "all".
249
- queryKey: ["activity", "by-provider", from ?? "all"],
250
- queryFn: () => byProvider(filter),
251
- // Keep prior window while range chips change so KPI/lists do not collapse.
252
- placeholderData: keepPreviousData,
230
+ queryKey: ["activity", "kpi-comparison", currentWindowStart],
231
+ queryFn: async () => {
232
+ const [current, previous] = await Promise.all([
233
+ byProvider({ from: currentWindowStart }),
234
+ byProvider({ from: previousWindowStart, to: previousWindowEnd }),
235
+ ]);
236
+ return { current: current.providers, previous: previous.providers };
237
+ },
253
238
  });
254
239
 
255
240
  const activityQuery = useQuery({
256
241
  refetchInterval: 15_000,
257
242
  retry: false,
258
- queryKey: ["activity", "activity-by-day", range, from ?? "all", providerFilter],
243
+ queryKey: ["activity", "activity-by-day", "all", providerFilter],
259
244
  queryFn: () =>
260
245
  activityByDay({
261
- ...filter,
262
246
  provider: providerFilter === "all" ? undefined : providerFilter,
263
247
  }),
264
- // Keep prior heatmap while provider / range switches — avoids spinner pushing layout.
248
+ // Keep prior heatmap while the provider switches — avoids spinner pushing layout.
265
249
  placeholderData: keepPreviousData,
266
250
  });
267
251
 
@@ -278,7 +262,7 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
278
262
  const histogramQuery = useQuery({
279
263
  refetchInterval: 15_000,
280
264
  retry: false,
281
- // Fixed window (050): the creations histogram ignores the range chips.
265
+ // Fixed 30-day window (050).
282
266
  queryKey: ["activity", "agent-creations", "last30", providerFilter],
283
267
  queryFn: () =>
284
268
  agentCreations({
@@ -288,10 +272,19 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
288
272
  placeholderData: keepPreviousData,
289
273
  });
290
274
 
275
+ const projectQuery = useQuery({
276
+ refetchInterval: 15_000,
277
+ retry: false,
278
+ queryKey: ["activity", "by-project", providerFilter],
279
+ queryFn: () =>
280
+ byProject({ provider: providerFilter === "all" ? undefined : providerFilter }),
281
+ placeholderData: keepPreviousData,
282
+ });
283
+
291
284
  const hourlyQuery = useQuery({
292
285
  refetchInterval: 15_000,
293
286
  retry: false,
294
- // Independent fixed window (059): range chips do not affect the hourly stream.
287
+ // Fixed 168-hour window (059).
295
288
  queryKey: ["activity", "activity-by-hour", "last168", providerFilter],
296
289
  queryFn: () =>
297
290
  activityByHour({
@@ -301,32 +294,28 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
301
294
  placeholderData: keepPreviousData,
302
295
  });
303
296
 
304
- const providers = query.data?.providers ?? [];
305
- const catalogProviders = catalogQuery.data?.providers ?? providers;
297
+ const providers = useMemo(() => query.data?.providers ?? [], [query.data]);
306
298
 
307
299
  const providerOptions = useMemo(
308
300
  () => [
309
- { id: "all", label: "All" },
310
- ...selectProviderOptions(catalogProviders, providerFilter),
301
+ { id: "all", label: m.global.allProviders },
302
+ ...selectProviderOptions(providers, providerFilter),
311
303
  ],
312
- [catalogProviders, providerFilter],
304
+ [providers, providerFilter, m],
313
305
  );
314
306
 
315
307
  useEffect(() => {
316
- if (providerFilter === "all") return;
317
- if (!catalogProviders.some((item) => item.provider === providerFilter)) {
308
+ if (providerFilter === "all" || !query.data) return;
309
+ if (!providers.some((item) => item.provider === providerFilter)) {
318
310
  setProviderFilter("all");
319
311
  }
320
- }, [catalogProviders, providerFilter]);
312
+ }, [providers, providerFilter, query.data]);
321
313
 
322
314
  const filteredProviders = useMemo(() => {
323
315
  if (providerFilter === "all") return providers;
324
- const inWindow = providers.filter((item) => item.provider === providerFilter);
325
- if (inWindow.length > 0) return inWindow;
326
- const catalog = catalogProviders.find((item) => item.provider === providerFilter);
327
- if (!catalog) return [];
328
- return [emptyProviderUsage(catalog.provider, catalog.label)];
329
- }, [catalogProviders, providerFilter, providers]);
316
+ const selected = providers.find((item) => item.provider === providerFilter);
317
+ return selected ? [selected] : [emptyProviderUsage(providerFilter)];
318
+ }, [providerFilter, providers]);
330
319
 
331
320
  const lists = useMemo(() => {
332
321
  if (providerFilter === "all") {
@@ -388,7 +377,7 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
388
377
  label: formatDisplayName(model),
389
378
  count,
390
379
  kind: "models" as const,
391
- countLabel: "messages",
380
+ unit: "prompts" as const,
392
381
  }))
393
382
  .sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
394
383
 
@@ -425,7 +414,7 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
425
414
  label: formatDisplayName(item.model),
426
415
  count: item.count,
427
416
  kind: "models" as const,
428
- countLabel: "messages",
417
+ unit: "prompts" as const,
429
418
  }))
430
419
  .sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
431
420
 
@@ -471,11 +460,6 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
471
460
  };
472
461
  }, [filteredProviders, providerFilter, query.data?.totals.workspaceCount]);
473
462
 
474
- const streaks = useMemo(
475
- () => computeStreaks(activityQuery.data?.days ?? []),
476
- [activityQuery.data],
477
- );
478
-
479
463
  const insights = useMemo(() => {
480
464
  return buildActivityInsights({
481
465
  days: activityQuery.data?.days ?? [],
@@ -488,70 +472,80 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
488
472
  chatAgents: summary.chatAgents,
489
473
  },
490
474
  workspaces: summary.workspaces,
475
+ averageSessionMs: lifetimeQuery.data?.averageEngagedMs,
476
+ multiTurn: lifetimeQuery.data,
491
477
  locale,
492
478
  });
493
- }, [activityQuery.data?.days, locale, summary]);
479
+ }, [activityQuery.data?.days, lifetimeQuery.data, locale, summary]);
494
480
 
495
481
  const kpi = useMemo(
496
482
  () =>
497
483
  buildActivityKpi({
498
- agents: summary.agents,
499
- days: activityQuery.data?.days ?? [],
484
+ sessions: summary.agents,
485
+ messages: summary.messages,
500
486
  locale,
501
- longestStreak: streaks.longest,
502
- longestAgent: lifetimeQuery.data?.longest
503
- ? {
504
- durationMs: lifetimeQuery.data.longest.durationMs,
505
- active: lifetimeQuery.data.longest.archivedAt == null,
506
- }
507
- : null,
508
487
  providers: filteredProviders,
488
+ allProviders: providers,
509
489
  providerFilter,
490
+ comparison: comparisonQuery.data,
510
491
  }),
511
492
  [
512
- activityQuery.data?.days,
493
+ comparisonQuery.data,
513
494
  filteredProviders,
514
- lifetimeQuery.data,
515
495
  locale,
516
496
  providerFilter,
517
- streaks.longest,
497
+ providers,
518
498
  summary.agents,
499
+ summary.messages,
519
500
  ],
520
501
  );
521
502
 
503
+ const scheme = chartColorScheme(theme.colors.surface0);
504
+ const providerEntries = useMemo<RankingEntry[]>(
505
+ () =>
506
+ providers.map((item) => ({
507
+ key: item.provider,
508
+ label: item.label,
509
+ color: providerColor(item.provider, scheme),
510
+ agents: item.agentCount,
511
+ messages: item.messageCount,
512
+ skills: item.skillCalls.exact + item.skillCalls.inferred,
513
+ mcp: item.mcpCalls,
514
+ })),
515
+ [providers, scheme],
516
+ );
517
+ const projectEntries = useMemo<RankingEntry[]>(
518
+ () =>
519
+ (projectQuery.data?.projects ?? []).map((item) => ({
520
+ key: item.key,
521
+ label: item.key === OTHER_PROJECT_KEY ? m.global.projectRanking.other : item.label,
522
+ color:
523
+ item.key === OTHER_PROJECT_KEY ? theme.colors.foregroundMuted : entityColor(item.key, scheme),
524
+ agents: item.agentCount,
525
+ messages: item.messageCount,
526
+ skills: item.skillCalls,
527
+ mcp: item.mcpCalls,
528
+ })),
529
+ [projectQuery.data, scheme, m, theme.colors.foregroundMuted],
530
+ );
531
+
522
532
  const styles = useMemo(
523
533
  () => ({
524
534
  screen: { flex: 1, backgroundColor: theme.colors.surface0 },
525
535
  content: {
526
- padding,
527
- paddingBottom: padding + 32,
528
- gap: layout.compact ? 24 : 32,
536
+ padding: page.padding,
537
+ paddingBottom: page.padding + 32,
538
+ gap: page.gap,
529
539
  maxWidth: 780,
530
540
  width: "100%" as const,
531
541
  alignSelf: "center" as const,
532
542
  },
533
543
  filterRow: {
534
544
  flexDirection: "row" as const,
535
- flexWrap: "wrap" as const,
536
545
  alignItems: "center" as const,
537
- justifyContent: "space-between" as const,
538
- gap: layout.compact ? 12 : 16,
539
- },
540
- tabRow: {
541
- flexDirection: "row" as const,
542
- flexWrap: "wrap" as const,
543
- alignItems: "center" as const,
544
- gap: layout.compact ? 12 : 16,
545
- },
546
- tab: {
547
- color: theme.colors.foregroundMuted,
548
- fontSize: 14,
549
- fontWeight: "500" as const,
550
- },
551
- tabActive: {
552
- color: theme.colors.foreground,
553
- fontSize: 14,
554
- fontWeight: "600" as const,
546
+ justifyContent: "flex-end" as const,
547
+ position: "relative" as const,
548
+ zIndex: 20,
555
549
  },
556
550
  columns: {
557
551
  flexDirection: layout.compact ? ("column" as const) : ("row" as const),
@@ -563,43 +557,27 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
563
557
  minWidth: 0,
564
558
  width: layout.compact ? ("100%" as const) : undefined,
565
559
  },
566
- block: {
567
- gap: 2,
568
- },
569
- titleRow: {
570
- flexDirection: "row" as const,
571
- alignItems: "center" as const,
572
- justifyContent: "space-between" as const,
573
- gap: 8,
574
- // + block gap 2 = 10 (compact) / 12 (regular), the chart sections' title gap.
575
- marginBottom: layout.compact ? 8 : 10,
576
- },
577
- blockTitle: {
578
- color: theme.colors.foreground,
579
- fontSize: layout.compact ? 13 : 15,
580
- fontWeight: "500" as const,
581
- flexShrink: 1,
582
- marginBottom: 0,
583
- },
584
- titleAction: {
585
- padding: 4,
586
- borderRadius: 6,
560
+ // Reserve the rank switch button's height in both columns (083).
561
+ columnHeader: {
562
+ minHeight: CONTROL.iconButton,
563
+ justifyContent: "center" as const,
564
+ marginBottom: titleGap(layout.compact) - ROW_GAP,
587
565
  },
588
566
  insightRow: {
589
567
  flexDirection: "row" as const,
590
568
  alignItems: "baseline" as const,
591
569
  justifyContent: "space-between" as const,
592
570
  gap: 8,
593
- paddingVertical: 9,
571
+ paddingVertical: ROW_PADDING.regular,
594
572
  },
595
573
  insightLabel: {
574
+ ...TEXT.body,
596
575
  color: theme.colors.foregroundMuted,
597
- fontSize: 14,
598
576
  flexShrink: 0,
599
577
  },
600
578
  insightValue: {
579
+ ...TEXT.body,
601
580
  color: theme.colors.foreground,
602
- fontSize: 14,
603
581
  textAlign: "right" as const,
604
582
  flex: 1,
605
583
  minWidth: 0,
@@ -608,36 +586,21 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
608
586
  flexDirection: "row" as const,
609
587
  alignItems: "center" as const,
610
588
  gap: 10,
611
- paddingVertical: 9,
589
+ paddingVertical: ROW_PADDING.regular,
612
590
  },
613
591
  rankName: {
592
+ ...TEXT.body,
614
593
  color: theme.colors.foreground,
615
- fontSize: 14,
616
594
  flex: 1,
617
595
  minWidth: 0,
618
-
619
596
  },
620
597
  rankMeta: {
598
+ ...TEXT.body,
621
599
  color: theme.colors.foregroundMuted,
622
- fontSize: 14,
623
600
  fontVariant: ["tabular-nums" as const],
624
601
  },
625
- emptyState: {
626
- paddingVertical: 48,
627
- alignItems: "center" as const,
628
- gap: 6,
629
- },
630
- emptyTitle: {
631
- color: theme.colors.foreground,
632
- fontSize: 19,
633
- fontWeight: "500" as const,
634
- },
635
- emptyHint: {
636
- color: theme.colors.foregroundMuted,
637
- fontSize: 14,
638
- },
639
602
  }),
640
- [theme, layout.compact, padding],
603
+ [theme, layout.compact, page.padding, page.gap],
641
604
  );
642
605
 
643
606
  // Keep prior results visible while refetching; spinner only on cold start.
@@ -646,39 +609,34 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
646
609
  (!activityQuery.data && activityQuery.isLoading) ||
647
610
  (!hourlyQuery.data && hourlyQuery.isLoading);
648
611
  const error = query.error ?? activityQuery.error ?? hourlyQuery.error;
612
+ const retry = () => {
613
+ void query.refetch();
614
+ void activityQuery.refetch();
615
+ void hourlyQuery.refetch();
616
+ };
649
617
  const showContent = filteredProviders.length > 0;
650
618
 
651
619
  return (
652
620
  <ScrollView style={styles.screen} contentContainerStyle={styles.content}>
653
- <View style={styles.filterRow}>
654
- <TextTabs
655
- options={RANGE_OPTIONS}
656
- value={range}
657
- onChange={(id) => setRange(id as RangeId)}
658
- styles={styles}
659
- />
660
- {providerOptions.length > 1 ? (
661
- <TextTabs
621
+ {providerOptions.length > 1 ? (
622
+ <View style={styles.filterRow}>
623
+ <ProviderDropdown
624
+ label={m.global.providerLabel}
662
625
  options={providerOptions}
663
626
  value={providerFilter}
664
627
  onChange={setProviderFilter}
665
- styles={styles}
628
+ colors={theme.colors}
629
+ triggerLabel={m.global.selectProvider}
630
+ closeLabel={m.global.closeProviderMenu}
666
631
  />
667
- ) : null}
668
- </View>
669
-
670
- {loading ? <ActivityIndicator color={theme.colors.accent} /> : null}
671
- {error ? (
672
- <Text style={{ color: theme.colors.statusDanger }}>
673
- {error instanceof Error ? error.message : String(error)}
674
- </Text>
632
+ </View>
675
633
  ) : null}
676
634
 
635
+ {loading ? <LoadingState color={theme.colors.accent} /> : null}
636
+ {error ? <ErrorState error={error} onRetry={retry} colors={theme.colors} /> : null}
637
+
677
638
  {filteredProviders.length === 0 && !loading && !error ? (
678
- <View style={styles.emptyState}>
679
- <Text style={styles.emptyTitle}>No usage yet</Text>
680
- <Text style={styles.emptyHint}>Agents, messages, skill and MCP calls will show up here</Text>
681
- </View>
639
+ <PageEmpty title={m.global.emptyTitle} hint={m.global.emptyHint} colors={theme.colors} />
682
640
  ) : null}
683
641
 
684
642
  {showContent ? (
@@ -688,22 +646,16 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
688
646
  {showContent ? (
689
647
  <ActivityHeatmap
690
648
  days={activityQuery.data?.days ?? []}
691
- from={from}
692
649
  colors={theme.colors}
693
650
  compact={layout.compact}
694
- mode={heatmapMode}
695
- onModeChange={setHeatmapMode}
696
- modeOptions={[
697
- { id: "daily", label: "Daily" },
698
- { id: "weekly", label: "Weekly" },
699
- { id: "cumulative", label: "Cumulative" },
700
- ]}
651
+ mode="daily"
701
652
  />
702
653
  ) : null}
703
654
 
704
655
  {showContent ? (
705
656
  <AgentCreations
706
657
  days={histogramQuery.data?.days ?? []}
658
+ activityDays={activityQuery.data?.days ?? []}
707
659
  windowDays={CREATIONS_WINDOW_DAYS}
708
660
  colors={theme.colors}
709
661
  compact={layout.compact}
@@ -721,11 +673,36 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
721
673
  />
722
674
  ) : null}
723
675
 
676
+ {showContent ? (
677
+ <RankingBars
678
+ title={m.global.providerRanking.title}
679
+ empty={m.global.providerRanking.empty}
680
+ entries={providerEntries}
681
+ highlight={providerFilter === "all" ? undefined : providerFilter}
682
+ colors={theme.colors}
683
+ compact={layout.compact}
684
+ locale={locale}
685
+ />
686
+ ) : null}
687
+
688
+ {showContent ? (
689
+ <RankingBars
690
+ title={m.global.projectRanking.title}
691
+ empty={m.global.projectRanking.empty}
692
+ entries={projectEntries}
693
+ colors={theme.colors}
694
+ compact={layout.compact}
695
+ locale={locale}
696
+ />
697
+ ) : null}
698
+
724
699
  {showContent ? (
725
700
  <View style={styles.columns}>
726
701
  <View style={styles.column}>
727
- <View style={styles.block}>
728
- <Text style={[styles.blockTitle, { marginBottom: layout.compact ? 8 : 10 }]}>Activity insights</Text>
702
+ <View style={{ gap: ROW_GAP }}>
703
+ <View style={styles.columnHeader}>
704
+ <SectionHeader title={m.insights.title} colors={theme.colors} compact={layout.compact} />
705
+ </View>
729
706
  {insights.map((row) => (
730
707
  <View key={row.label} style={styles.insightRow}>
731
708
  <Text style={styles.insightLabel}>{row.label}</Text>
@@ -739,19 +716,17 @@ export function GlobalUsageSurface({ theme, layout, navigation }: PluginSurfaceP
739
716
 
740
717
  <View style={styles.column}>
741
718
  <RankList
742
- title={rankTitle(rankKind)}
743
- items={(
744
- rankKind === "skills"
745
- ? lists.skills
746
- : rankKind === "mcp"
747
- ? lists.mcp
748
- : lists.models
749
- ).slice(0, LIST_LIMIT)}
750
- empty={rankEmpty(rankKind)}
719
+ title={m.global.rankTitle[rankKind]}
720
+ items={lists[rankKind]}
721
+ visibleRows={insights.length}
722
+ empty={m.global.rankEmpty[rankKind]}
751
723
  styles={styles}
752
724
  colors={theme.colors}
725
+ compact={layout.compact}
726
+ units={m.units}
753
727
  headerAction={{
754
- ...rankHeaderAction(rankKind),
728
+ icon: rankShowIcon(rankKind),
729
+ accessibilityLabel: m.global.rankShow[nextRankKind(rankKind)],
755
730
  onPress: () => setRankKind((prev) => nextRankKind(prev)),
756
731
  }}
757
732
  />