@koinzhang/paseo-plugin-activity 0.1.0 → 0.3.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 (60) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +85 -0
  3. package/client/activity-heatmap.tsx +72 -14
  4. package/client/formatted-time.tsx +23 -0
  5. package/client/global-surface.tsx +24 -25
  6. package/client/hidden-pill-recheck.test.ts +33 -0
  7. package/client/hidden-pill-recheck.ts +22 -0
  8. package/client/panel.tsx +116 -107
  9. package/client/pill-directory.test.ts +92 -0
  10. package/client/pill-directory.ts +79 -0
  11. package/client/pill.tsx +23 -23
  12. package/client/range.ts +20 -0
  13. package/client/usage-popover.tsx +75 -84
  14. package/client/usage-query.tsx +8 -3
  15. package/client/usage-stats.tsx +7 -5
  16. package/client/use-agent-turn-end.ts +69 -0
  17. package/client/workspace/agent-row.tsx +167 -0
  18. package/client/workspace/agents-section.tsx +330 -0
  19. package/client/workspace/constants.ts +147 -0
  20. package/client/workspace/display-menu.tsx +116 -0
  21. package/client/workspace/filters.ts +30 -0
  22. package/client/workspace/list-host-agents.test.ts +45 -0
  23. package/client/workspace/list-host-agents.ts +90 -0
  24. package/client/workspace/panel.tsx +964 -0
  25. package/client/workspace/rank-section.tsx +131 -0
  26. package/client/workspace/running-indicator.tsx +54 -0
  27. package/client/workspace/status-cache.test.ts +62 -0
  28. package/client/workspace/status-cache.ts +19 -0
  29. package/client/workspace/terminal-preview.test.ts +17 -0
  30. package/client/workspace/terminal-preview.ts +10 -0
  31. package/client/workspace/terminals-section.tsx +155 -0
  32. package/client/workspace-panel.tsx +2 -0
  33. package/index.client.tsx +20 -13
  34. package/index.server.ts +13 -0
  35. package/package.json +9 -3
  36. package/server/agents.test.ts +36 -1
  37. package/server/agents.ts +9 -5
  38. package/server/background-sync.test.ts +14 -3
  39. package/server/background-sync.ts +16 -5
  40. package/server/handlers-query.test.ts +82 -3
  41. package/server/handlers.ts +89 -6
  42. package/server/messages.test.ts +8 -2
  43. package/server/skill-path.ts +3 -20
  44. package/server/store.test.ts +13 -0
  45. package/server/store.ts +2 -2
  46. package/shared/activity.test.ts +22 -12
  47. package/shared/activity.ts +8 -13
  48. package/shared/agent-page-size.test.ts +11 -0
  49. package/shared/agent-title-search.test.ts +28 -0
  50. package/shared/agent-title-search.ts +12 -0
  51. package/shared/explorer-agent-display.ts +30 -0
  52. package/shared/format.test.ts +41 -16
  53. package/shared/format.ts +26 -17
  54. package/shared/home-path.ts +19 -0
  55. package/shared/insights.test.ts +38 -18
  56. package/shared/insights.ts +38 -19
  57. package/shared/list-agent-pages.test.ts +51 -0
  58. package/shared/list-agent-pages.ts +31 -0
  59. package/shared/usage.test.ts +248 -0
  60. package/shared/usage.ts +336 -11
package/CHANGELOG.md ADDED
@@ -0,0 +1,81 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@koinzhang/paseo-plugin-activity` are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.3.0] - 2026-09-19
11
+
12
+ ### Added
13
+
14
+ - Workspace Activity panel **Terminals** section: lists open terminals via the host SDK (`paseo.terminals.list`), tap-to-expand live output preview (`capture`, latest 8 lines, ANSI stripped, 5s polling), and a per-row close button (`kill`, optimistic removal with rollback toast); terminal cwd collapses the home directory to `~` (new `usage.host-info` RPC); the section is hidden when no terminals are open.
15
+ - Explorer Agents rows show a warning badge (ShieldAlert icon, plus a count when there are multiple) when the host reports pending permission requests; those agents also rank first with other attention-worthy agents.
16
+ - Explorer Agents row bot icon uses theme status colors for attention: success for finished-but-unread turns, warning for pending permissions (badge kept), danger for failed agents; the icon returns to muted once the host clears attention after viewing.
17
+ - Explorer Agents rows show a host-style spinning ring at the bottom-right of the bot icon while `status = "running"`; it disappears when the turn ends.
18
+ - Explorer agent status (permission badge, attention colors, running spinner) accelerates from directory `agent_update` pushes (incremental status cache); the 15s poll remains the completeness guarantee and does not call `agents.list({ subscribe })` (avoids stealing the host's single observation slot on Paseo 0.8).
19
+ - Agent panel / composer pill usage queries refresh on real timeline turn terminal events (`turn_completed` / `turn_failed` / `turn_canceled` / `replacement`, 300ms debounce + 2s ingest settle); Workspace panel gets a best-effort directory hint when an agent leaves `running` / `initializing`, with the 15s query poll owning completeness. Pill empty-state poll slowed from 1.5s to 5s. Global surface and Terminals keep their existing poll intervals.
20
+ - Shared activity time formatting: `FormattedTime` / `formatActivityTime` (app language + locale, 24-hour clock; same-day time only, same-year month/day + time, else include year) used by Agent panel, Workspace rank / Updated meta, and the composer popover.
21
+
22
+ ### Changed
23
+
24
+ - Agent Activity panel and composer popover: Skills / MCP detail uses the same header toggle icon pattern as Workspace rank (no tab strip).
25
+ - Agent Activity panel KPIs use dense `UsageStats` (aligned with Workspace).
26
+ - Workspace skills / MCP rank toggle is hidden when only one kind has data.
27
+
28
+ ### Fixed
29
+
30
+ - Workspace agent status enrichment filters by placement `projectId` (daemon shape), not `projects.list` remote keys — stops the 15s poll from wiping live permission / attention state.
31
+ - In-flight status polls are cancelled before applying a newer directory push, so stale responses cannot overwrite live agent state.
32
+ - Skill path resolution refreshes empty handles and falls back to home roots when project cwd lookup fails.
33
+
34
+ ## [0.2.0] - 2026-09-19
35
+
36
+ ### Added
37
+
38
+ - Heatmap month focus: hovering a month label highlights that month's cells and dims the rest.
39
+ - Workspace Activity panel in the Explorer sidebar: workspace-scoped KPIs (shell calls / file reads / file writes / messages), per-agent ranking (new `usage.agents` RPC), and top skills / MCP; the Workspace Activity Command Center item opens it.
40
+ - Explorer Agents title search: a header search icon expands an animated inline pill; case-insensitive tokenized match on title (falls back to agent id) that stacks with Status / Lifecycle filters, sort, and grouping; the query is session-only.
41
+ - Explorer Agents archive / unarchive row actions: Active rows show Archive (host `agents.ref(id).archive()`), Archived rows show Unarchive (new `usage.agent.unarchive` RPC → `paseo agent reload`), with optimistic list updates, error toast, and the local registry `archived_at` cleared on unarchive.
42
+ - Agent panel Messages KPI via `usage.summary.messageCount` (same filter as tools).
43
+ - Architecture overview for Global / Workspace / Agent scopes (`docs/architecture.md`).
44
+ - Explorer Agents list pager (40 per page); controls hidden when there is only one page.
45
+ - Host `agents.list` pagination for Explorer status enrichment and background history sync.
46
+
47
+ ### Changed
48
+
49
+ - Coding vs chat now counts active agents instead of ops: an agent counts as coding when it has a file write/edit/delete or a mutating shell command; created-only agents are excluded from both buckets.
50
+ - Insights rows reordered (calendar → preference → structure); Top provider restored (messages-weighted, All view only) and Tools per message removed.
51
+ - Command Center items renamed: Open Activity (all providers) → Activity, Activity → Agent Activity.
52
+ - Heatmap title renamed from Tool activity to Activity.
53
+ - Smaller headings and tighter section spacing across the global surface and heatmap.
54
+ - Explorer Activity panel: header removed (branch / workspace name and Today / 7D / 30D / All chips) so KPIs cover the workspace's full history; denser KPIs (shell / file reads / file writes / messages only); Active agent rows open the conversation from anywhere in the row; agent display menu (floating card below the header icon with hover flyout submenus matching the host sidebar menu; sort by updated / created / name / messages / status with attention-worthy agents first; group by None / Provider / Status; multi-select Status Active / Archived and Lifecycle Idle / Running / Error / Closed; Show toggles for provider / calls / messages / updated; `usage.agents` returns `updatedAt` and `archivedAt`); Command Center item Workspace Activity opens the panel in the Explorer; skills / MCP share one ranked list toggled by the header icon; hidden scrollbars avoid layout shift when filters change.
55
+ - Explorer Agents display preferences (Sort / Group / Show / Status / Lifecycle) persist across workspaces, plugin reloads, and daemon restarts in host-scoped `explorer-agent-display` settings; defaults are sort Updated, group None, Status Active, all lifecycles, no extra Show fields.
56
+ - Workspace Activity panel split into `client/workspace/` modules; Workspace Messages KPI reads `usage.summary.messageCount`.
57
+
58
+ ### Removed
59
+
60
+ - Command Center Export activity report item; the `usage.export` RPC stays available.
61
+
62
+ ### Fixed
63
+
64
+ - Heatmap keeps its 52-week layout for Today / 7D / 30D ranges.
65
+ - Hardened heatmap color mixing against invalid theme color values.
66
+
67
+ ## [0.1.0] - 2026-09-19
68
+
69
+ ### Added
70
+
71
+ - Initial release: local SQLite-backed usage analytics for tools, agents, messages, and models.
72
+ - Timeline ingestion with silent historical backfill; queries read the local database only.
73
+ - Composer pill, agent workspace panel, and Activity sidebar (global view grouped by provider).
74
+ - Heatmap, KPIs, insights, most used models, and a provider filter limited to the top 5.
75
+ - Command Center entries: open panels and export a markdown usage report.
76
+ - Plugin renamed from `tool-usage` to `activity`, migrating the old data directory automatically.
77
+
78
+ [Unreleased]: https://github.com/koinzhang/paseo-plugins/compare/activity-v0.3.0...HEAD
79
+ [0.3.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.3.0
80
+ [0.2.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.2.0
81
+ [0.1.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.1.0
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Activity
2
+
3
+ Activity for Paseo: local usage analytics **and** workspace agent management.
4
+
5
+ It still answers “how am I using Paseo” (tools, messages, models, habits). With the Explorer **Workspace Activity** panel it also becomes a **vertical ops surface** for the agents in the current workspace — sort, filter, search, open, archive — with live attention cues, open terminals, KPIs, and top skills / MCP.
6
+
7
+ | Scope | Role |
8
+ |---|---|
9
+ | **Global** | Cross-workspace habits: heatmap, provider filter, insights, most-used skills / MCP / models |
10
+ | **Workspace** | Per-workspace agent fleet: ranked list + display prefs + archive; live status (permission / finished / error / running); open Terminals; shell / file / messages KPIs; times via shared `FormattedTime` |
11
+ | **Agent** | Current session: dense tool KPIs, Skills / MCP header toggle, SKILL.md reader, composer pill; refreshes on timeline turn end |
12
+
13
+ Architecture notes: [docs/architecture.md](./docs/architecture.md).
14
+
15
+ ## What is counted
16
+
17
+ Ingests every agent's Paseo timeline into a local SQLite database. Queries read that database; the timeline and `agents.list` are ingestion / backfill / live-status sources only.
18
+
19
+ | Dimension | What is counted |
20
+ |---|---|
21
+ | Tools | Skill / MCP / shell / file calls; skills classified into exact / inferred / low confidence tiers |
22
+ | Agents | Every created agent (registry with archive metadata) |
23
+ | Messages | User-sent messages |
24
+ | Models | Model at send time (weighted by messages; global view) |
25
+
26
+ ## Where it shows up
27
+
28
+ - **Sidebar Activity** — global view by provider (heatmap, KPIs, insights, most used)
29
+ - **Explorer → Activity** — workspace agents as a management list (search / sort / group / status / lifecycle / archive), live attention (permission badge, status colors, running spinner; directory push + 15s poll), open Terminals (list / preview / close), plus workspace KPIs and top skills / MCP (toggle hidden when only one kind has data); usage queries get a best-effort refresh hint when agents leave running
30
+ - **Agent workspace panel** — per-agent tool detail (dense KPI including messages / Skills / MCP toggle / SKILL.md); refreshes on timeline turn terminal events
31
+ - **Composer pill** — current agent's skill / MCP summary (header toggle); hidden when empty; refreshes on timeline turn end (5s empty poll fallback)
32
+ - **Command Center** — Activity · Workspace Activity · Agent Activity
33
+
34
+ ## Data
35
+
36
+ Everything lives on the daemon machine in `~/.paseo/plugin-data/activity/` (SQLite `usage.db`). Nothing is sent anywhere.
37
+
38
+ ## Install
39
+
40
+ Requires Paseo >= 0.8.0.
41
+
42
+ From Git (Paseo 0.8 and later):
43
+
44
+ ```bash
45
+ paseo plugin add koinzhang/paseo-plugins --path activity
46
+ ```
47
+
48
+ From npm (Paseo 0.9 and later; this is the source paseo.cafe hands to Paseo 0.9+):
49
+
50
+ ```bash
51
+ paseo plugin install npm:@koinzhang/paseo-plugin-activity
52
+ ```
53
+
54
+ After source changes, reload and check status:
55
+
56
+ ```bash
57
+ paseo plugin reload activity
58
+ paseo plugin logs activity
59
+ paseo plugin ls
60
+ ```
61
+
62
+ ## Limitations
63
+
64
+ - Analytics and the agent registry are local to each daemon: every machine keeps its own database, and there is no cross-host aggregation.
65
+ - Numbers are reconstructed from the Paseo timeline; items that do not report a model or skill cannot be attributed for that dimension.
66
+ - Skill classification is heuristic (exact / inferred / low confidence); check the tier before trusting a count.
67
+ - Workspace Activity focuses on agent operations for the current workspace; heatmap / provider / model breakdowns stay on the global sidebar.
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ npm install
73
+ npm run typecheck
74
+ npm test
75
+ ```
76
+
77
+ This plugin is spec-driven: read [specs/README.md](./specs/README.md) before coding, then the matching numbered directory.
78
+
79
+ ## Publish
80
+
81
+ Release history: [CHANGELOG.md](./CHANGELOG.md) (current **0.3.0**). npm releases go through a GitHub Release tag `activity-vX.Y.Z` (not push-to-`main` alone). Steps: [CONTRIBUTING.md § Publishing to npm](../CONTRIBUTING.md#publishing-to-npm).
82
+
83
+ ## License
84
+
85
+ [MIT](../LICENSE) © koinzhang
@@ -10,18 +10,23 @@ type ThemeColors = {
10
10
  surface0: string; surface1: string; surface2: string;
11
11
  };
12
12
 
13
+ type HoveredMonth = { year: number; month: number };
14
+
13
15
  // Derive the activity palette from the active theme.
14
16
  function mix(base: string, accent: string, amount: number): string {
15
- const parse = (value: string) => {
16
- const hex = value.replace("#", "");
17
+ const parse = (value: string): number[] | null => {
18
+ const hex = value.replace("#", "").trim();
17
19
  const expanded = hex.length === 3 || hex.length === 4
18
20
  ? hex.split("").map((c) => c + c).join("")
19
21
  : hex;
20
22
  // Use first 6 digits only — ignore trailing alpha on 8-digit hex.
21
23
  const rgb = expanded.slice(0, 6);
24
+ if (!/^[0-9a-fA-F]{6}$/.test(rgb)) return null;
22
25
  return [0, 2, 4].map((i) => parseInt(rgb.slice(i, i + 2), 16));
23
26
  };
24
- const a = parse(base); const b = parse(accent);
27
+ const a = parse(base);
28
+ const b = parse(accent);
29
+ if (!a || !b) return base;
25
30
  return `rgb(${a.map((v, i) => Math.round(v + (b[i]! - v) * amount)).join(",")})`;
26
31
  }
27
32
 
@@ -29,6 +34,12 @@ function plural(count: number, singular: string, pluralForm = `${singular}s`): s
29
34
  return `${count.toLocaleString()} ${count === 1 ? singular : pluralForm}`;
30
35
  }
31
36
 
37
+ function cellInMonth(dateKey: string, hovered: HoveredMonth | null): boolean {
38
+ if (!hovered) return false;
39
+ const [year, month] = dateKey.split("-").map(Number);
40
+ return year === hovered.year && month === hovered.month + 1;
41
+ }
42
+
32
43
  export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChange, modeOptions }: {
33
44
  days: readonly ActivityDay[]; from?: string; colors: ThemeColors; compact?: boolean;
34
45
  mode: HeatmapMode; onModeChange: (mode: HeatmapMode) => void;
@@ -41,7 +52,12 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
41
52
  const [tooltipSize, setTooltipSize] = useState({ width: 220, height: 28 });
42
53
  const [selected, setSelected] = useState<string | null>(null);
43
54
  const [hovered, setHovered] = useState<string | null>(null);
44
- useEffect(() => { setSelected(null); setHovered(null); }, [from, mode, days]);
55
+ const [hoveredMonth, setHoveredMonth] = useState<HoveredMonth | null>(null);
56
+ useEffect(() => {
57
+ setSelected(null);
58
+ setHovered(null);
59
+ setHoveredMonth(null);
60
+ }, [from, mode, days]);
45
61
  const { weeks, months, max } = useMemo(() => buildActivityCalendar(days, mode, from, new Date(), locale), [days, mode, from, locale]);
46
62
  const gap = compact ? 2 : 3;
47
63
  // Fit the full year into the measured width (no min floor — avoid horizontal overflow).
@@ -69,13 +85,13 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
69
85
  const tooltipText = active
70
86
  ? `${plural(active.skills, "skill")}, ${plural(active.mcp, "mcp")}, ${plural(active.agents, "agent")}, ${plural(active.messages, "message")} ${datePrefix} ${dateLabel}`
71
87
  : "";
72
- const muted = { color: colors.foregroundMuted, fontSize: 12 };
73
88
  const axisWidth = needsScroll ? gridWidth : width;
74
89
  const modeLabel = mode === "weekly" ? "Week containing" : mode === "cumulative" ? "Through" : "";
90
+ const monthFocus = hoveredMonth != null;
75
91
  return (
76
- <View style={{ gap: compact ? 16 : 22 }} onLayout={event => setWidth(event.nativeEvent.layout.width)}>
92
+ <View style={{ gap: compact ? 10 : 12 }} onLayout={event => setWidth(event.nativeEvent.layout.width)}>
77
93
  <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
78
- <Text style={{ color: colors.foreground, fontSize: compact ? 17 : 20, fontWeight: "500" }}>Tool activity</Text>
94
+ <Text style={{ color: colors.foreground, fontSize: compact ? 13 : 15, fontWeight: "500" }}>Activity</Text>
79
95
  <View style={{ flexDirection: "row", gap: compact ? 14 : 20 }}>
80
96
  {modeOptions.map(option => (
81
97
  <Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: mode === option.id }} onPress={() => onModeChange(option.id)} style={{ paddingVertical: 6 }}>
@@ -98,6 +114,22 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
98
114
  <View key={i} style={{ gap }}>
99
115
  {week.map(cell => {
100
116
  const hidden = cell.future || cell.excluded;
117
+ const inMonth = cellInMonth(cell.key, hoveredMonth);
118
+ const level = activityLevel(cell.total, max);
119
+ const base = palette[level]!;
120
+ // Focus = leave target month as-is; gently mute others toward surface2
121
+ // (same space as empty cells — preserves activity hue, avoids surface0 parse issues).
122
+ const fill =
123
+ hidden
124
+ ? base
125
+ : monthFocus && inMonth
126
+ ? mix(base, colors.accent, 0.04)
127
+ : base;
128
+ const opacity = hidden
129
+ ? 0
130
+ : monthFocus && !inMonth
131
+ ? 0.64
132
+ : 1;
101
133
  return (
102
134
  <Pressable key={cell.key} disabled={hidden} accessibilityRole="button"
103
135
  accessibilityLabel={`${modeLabel} ${cell.key}: ${cell.total} activity, ${cell.skills} skills, ${cell.mcp} MCP, ${cell.agents} agents, ${cell.messages} messages`}
@@ -105,19 +137,45 @@ export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChang
105
137
  onHoverIn={() => setHovered(cell.key)} onHoverOut={() => setHovered(null)}
106
138
  onFocus={() => setHovered(cell.key)} onBlur={() => setHovered(null)}
107
139
  onPress={() => setSelected(prev => prev === cell.key ? null : cell.key)}
108
- style={{ width: cellSize, height: cellSize, borderRadius: Math.max(2, cellSize / 4),
109
- backgroundColor: palette[activityLevel(cell.total, max)], opacity: hidden ? 0 : 1 }} />
140
+ style={{
141
+ width: cellSize,
142
+ height: cellSize,
143
+ borderRadius: Math.max(2, cellSize / 4),
144
+ backgroundColor: fill,
145
+ opacity,
146
+ }} />
110
147
  );
111
148
  })}
112
149
  </View>
113
150
  ))}
114
151
  </View>
115
152
  <View style={{ height: 24, marginTop: 10, flexDirection: "row", justifyContent: "space-between" }}>
116
- {months.map((item, i) => (
117
- <Text key={`${item.label}-${i}`} numberOfLines={1} style={muted}>
118
- {item.label}
119
- </Text>
120
- ))}
153
+ {months.map((item, i) => {
154
+ const activeMonth =
155
+ hoveredMonth?.year === item.year && hoveredMonth.month === item.month;
156
+ return (
157
+ <Pressable
158
+ key={`${item.year}-${item.month}-${i}`}
159
+ accessibilityRole="button"
160
+ accessibilityLabel={`Highlight ${item.label}`}
161
+ onHoverIn={() => setHoveredMonth({ year: item.year, month: item.month })}
162
+ onHoverOut={() => setHoveredMonth(null)}
163
+ onFocus={() => setHoveredMonth({ year: item.year, month: item.month })}
164
+ onBlur={() => setHoveredMonth(null)}
165
+ style={{ paddingVertical: 2 }}
166
+ >
167
+ <Text
168
+ numberOfLines={1}
169
+ style={{
170
+ color: activeMonth ? colors.foreground : colors.foregroundMuted,
171
+ fontSize: 12,
172
+ }}
173
+ >
174
+ {item.label}
175
+ </Text>
176
+ </Pressable>
177
+ );
178
+ })}
121
179
  </View>
122
180
  </View>
123
181
  </ScrollView>
@@ -0,0 +1,23 @@
1
+ import type { ReactNode } from "react";
2
+ import { Text, type TextStyle } from "react-native";
3
+ import { formatActivityTime } from "../shared/format.ts";
4
+ import { useAppLanguage } from "./use-app-language.ts";
5
+
6
+ /**
7
+ * ISO timestamp with app language (fallback `en`) + Intl locale style.
8
+ * Today → time only; same year → month/day + time; otherwise includes the year.
9
+ */
10
+ export function FormattedTime({
11
+ iso,
12
+ style,
13
+ prefix,
14
+ }: {
15
+ iso: string | null | undefined;
16
+ style?: TextStyle;
17
+ /** e.g. `"Last "` — concatenated before the stamp */
18
+ prefix?: string;
19
+ }): ReactNode {
20
+ const locale = useAppLanguage();
21
+ const stamp = formatActivityTime(iso, locale);
22
+ return <Text style={style}>{prefix ? `${prefix}${stamp}` : stamp}</Text>;
23
+ }
@@ -29,8 +29,7 @@ import { mcpServerColor } from "./rank-color.ts";
29
29
  import { selectProviderOptions } from "./provider-filter.ts";
30
30
  import { useAppLanguage } from "./use-app-language.ts";
31
31
  import { buildActivityInsights, ACTIVITY_LIST_LIMIT } from "../shared/insights.ts";
32
-
33
- type RangeId = "all" | "7d" | "30d" | "today";
32
+ import { rangeFrom, RANGE_OPTIONS, type RangeId } from "./range.ts";
34
33
 
35
34
  /** Max rows for Activity insights and Most used skills / MCP. */
36
35
  const LIST_LIMIT = ACTIVITY_LIST_LIMIT;
@@ -52,6 +51,8 @@ function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem
52
51
  shellTop: [],
53
52
  models: [],
54
53
  agentCount: 0,
54
+ codingAgentCount: 0,
55
+ chatAgentCount: 0,
55
56
  workspaceCount: 0,
56
57
  messageCount: 0,
57
58
  callCount: 0,
@@ -60,17 +61,6 @@ function emptyProviderUsage(provider: string, label?: string): ProviderUsageItem
60
61
 
61
62
 
62
63
 
63
- function rangeFrom(id: RangeId): string | undefined {
64
- if (id === "all") return undefined;
65
- if (id === "today") {
66
- const d = new Date();
67
- d.setHours(0, 0, 0, 0);
68
- return d.toISOString();
69
- }
70
- const days = id === "7d" ? 7 : 30;
71
- return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString();
72
- }
73
-
74
64
  function formatCount(value: number): string {
75
65
  if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
76
66
  if (value >= 10_000) return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
@@ -405,6 +395,8 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
405
395
  let fileReads = 0;
406
396
  let fileWrites = 0;
407
397
  let agents = 0;
398
+ let codingAgents = 0;
399
+ let chatAgents = 0;
408
400
  let messages = 0;
409
401
  for (const item of filteredProviders) {
410
402
  skills += item.skillCalls.exact + item.skillCalls.inferred;
@@ -413,13 +405,26 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
413
405
  fileReads += item.fileReads;
414
406
  fileWrites += item.fileWrites;
415
407
  agents += item.agentCount;
408
+ codingAgents += item.codingAgentCount;
409
+ chatAgents += item.chatAgentCount;
416
410
  messages += item.messageCount;
417
411
  }
418
412
  const workspaces =
419
413
  providerFilter === "all"
420
414
  ? (query.data?.totals.workspaceCount ?? 0)
421
415
  : (filteredProviders[0]?.workspaceCount ?? 0);
422
- return { skills, mcp, shell, fileReads, fileWrites, agents, messages, workspaces };
416
+ return {
417
+ skills,
418
+ mcp,
419
+ shell,
420
+ fileReads,
421
+ fileWrites,
422
+ agents,
423
+ codingAgents,
424
+ chatAgents,
425
+ messages,
426
+ workspaces,
427
+ };
423
428
  }, [filteredProviders, providerFilter, query.data?.totals.workspaceCount]);
424
429
 
425
430
  const streaks = useMemo(
@@ -435,9 +440,8 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
435
440
  mcp: summary.mcp,
436
441
  agents: summary.agents,
437
442
  messages: summary.messages,
438
- shell: summary.shell,
439
- fileReads: summary.fileReads,
440
- fileWrites: summary.fileWrites,
443
+ codingAgents: summary.codingAgents,
444
+ chatAgents: summary.chatAgents,
441
445
  longestStreak: streaks.longest,
442
446
  },
443
447
  providers: filteredProviders,
@@ -468,7 +472,7 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
468
472
  content: {
469
473
  padding,
470
474
  paddingBottom: padding + 32,
471
- gap: layout.compact ? 28 : 40,
475
+ gap: layout.compact ? 24 : 32,
472
476
  maxWidth: 780,
473
477
  width: "100%" as const,
474
478
  alignSelf: "center" as const,
@@ -518,7 +522,7 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
518
522
  },
519
523
  blockTitle: {
520
524
  color: theme.colors.foreground,
521
- fontSize: 19,
525
+ fontSize: layout.compact ? 13 : 15,
522
526
  fontWeight: "500" as const,
523
527
  flexShrink: 1,
524
528
  marginBottom: 0,
@@ -593,12 +597,7 @@ export function GlobalUsageSurface({ theme, layout }: PluginSurfaceProps) {
593
597
  <ScrollView style={styles.screen} contentContainerStyle={styles.content}>
594
598
  <View style={styles.filterRow}>
595
599
  <TextTabs
596
- options={[
597
- { id: "all", label: "All time" },
598
- { id: "today", label: "Today" },
599
- { id: "7d", label: "7 days" },
600
- { id: "30d", label: "30 days" },
601
- ]}
600
+ options={RANGE_OPTIONS}
602
601
  value={range}
603
602
  onChange={(id) => setRange(id as RangeId)}
604
603
  styles={styles}
@@ -0,0 +1,33 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { createHiddenPillRecheck } from "./hidden-pill-recheck.ts";
4
+ import type { UsagePillData } from "./pill-data-cache.ts";
5
+ const empty: UsagePillData = { skills: [], mcpTools: [] };
6
+ const populated: UsagePillData = { skills: [], mcpTools: [{ server: "paseo", tool: "read", count: 1, failures: 0, lastUsedAt: null }] };
7
+
8
+ test("hidden empty pill stays hidden, but delayed ingestion can show it", async () => {
9
+ let data = empty;
10
+ let shows = 0;
11
+ const check = createHiddenPillRecheck(async () => data, () => true, () => { shows++; });
12
+ await check(); await check();
13
+ assert.equal(shows, 0);
14
+ data = populated;
15
+ await check();
16
+ assert.equal(shows, 1);
17
+ });
18
+
19
+ test("hidden rechecks coalesce and cannot show a removed pill", async () => {
20
+ let finish!: (data: UsagePillData) => void;
21
+ let current = true;
22
+ let loads = 0;
23
+ let shows = 0;
24
+ const check = createHiddenPillRecheck(() => { loads++; return new Promise(resolve => { finish = resolve; }); },
25
+ () => current, () => { shows++; });
26
+ const first = check();
27
+ await check();
28
+ assert.equal(loads, 1);
29
+ current = false;
30
+ finish(populated);
31
+ await first;
32
+ assert.equal(shows, 0);
33
+ });
@@ -0,0 +1,22 @@
1
+ import { pillDataIsEmpty, type UsagePillData } from "./pill-data-cache.ts";
2
+
3
+ /** Recheck hidden pills without showing empty chrome; discard results after removal. */
4
+ export function createHiddenPillRecheck(
5
+ load: () => Promise<UsagePillData>,
6
+ isCurrentAndHidden: () => boolean,
7
+ show: (data: UsagePillData) => void,
8
+ ): () => Promise<void> {
9
+ let running = false;
10
+ return async () => {
11
+ if (running || !isCurrentAndHidden()) return;
12
+ running = true;
13
+ try {
14
+ const data = await load();
15
+ if (isCurrentAndHidden() && !pillDataIsEmpty(data)) show(data);
16
+ } catch (error) {
17
+ if (isCurrentAndHidden()) console.error("[activity] hidden pill recheck failed", error);
18
+ } finally {
19
+ running = false;
20
+ }
21
+ };
22
+ }