@koinzhang/paseo-plugin-activity 0.5.0 → 0.7.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 (74) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/README.md +15 -8
  3. package/client/activity-heatmap.tsx +126 -93
  4. package/client/agent-creations.tsx +216 -0
  5. package/client/attention-pill.tsx +16 -5
  6. package/client/attention-popover.tsx +19 -23
  7. package/client/color-mix.test.ts +27 -0
  8. package/client/color-mix.ts +38 -0
  9. package/client/design-tokens.test.ts +39 -0
  10. package/client/design-tokens.ts +168 -0
  11. package/client/fit-text.test.ts +41 -0
  12. package/client/fit-text.ts +33 -0
  13. package/client/formatted-time.tsx +4 -4
  14. package/client/global-surface.tsx +316 -275
  15. package/client/header-button.ts +136 -0
  16. package/client/hourly-activity-timeline.tsx +425 -0
  17. package/client/measured-width.ts +72 -0
  18. package/client/panel-visibility.test.ts +25 -0
  19. package/client/panel-visibility.ts +45 -0
  20. package/client/panel.tsx +83 -108
  21. package/client/provider-dropdown.tsx +131 -0
  22. package/client/provider-filter.test.ts +17 -13
  23. package/client/provider-filter.ts +5 -7
  24. package/client/range.test.ts +44 -0
  25. package/client/range.ts +14 -0
  26. package/client/rank-color.test.ts +108 -14
  27. package/client/rank-color.ts +261 -48
  28. package/client/ranking-bars.tsx +291 -0
  29. package/client/ui.tsx +339 -0
  30. package/client/usage-popover.tsx +62 -134
  31. package/client/usage-stats.tsx +137 -8
  32. package/client/use-agent-turn-end.ts +2 -1
  33. package/client/use-app-language.ts +17 -0
  34. package/client/web.ts +73 -18
  35. package/client/workspace/agent-row.tsx +18 -25
  36. package/client/workspace/agents-section.tsx +23 -20
  37. package/client/workspace/constants.ts +6 -6
  38. package/client/workspace/display-menu.tsx +5 -4
  39. package/client/workspace/filters.test.ts +1 -1
  40. package/client/workspace/filters.ts +4 -2
  41. package/client/workspace/panel.tsx +176 -104
  42. package/client/workspace/rank-section.tsx +157 -44
  43. package/client/workspace/terminals-section.tsx +13 -9
  44. package/index.client.tsx +40 -20
  45. package/index.server.ts +63 -31
  46. package/package.json +2 -2
  47. package/paseo-plugin.json +2 -1
  48. package/server/agents.ts +20 -2
  49. package/server/background-sync.test.ts +43 -0
  50. package/server/background-sync.ts +43 -4
  51. package/server/handlers-query.test.ts +252 -1
  52. package/server/handlers.ts +174 -13
  53. package/server/ingest.test.ts +8 -0
  54. package/server/messages.test.ts +96 -1
  55. package/server/prompt-dedupe.ts +52 -0
  56. package/server/rpc-cache.test.ts +74 -0
  57. package/server/rpc-cache.ts +48 -0
  58. package/server/store.test.ts +122 -0
  59. package/server/store.ts +313 -19
  60. package/server/ttl-cache.ts +3 -0
  61. package/shared/activity.test.ts +159 -6
  62. package/shared/activity.ts +140 -5
  63. package/shared/classify.test.ts +1 -0
  64. package/shared/classify.ts +4 -1
  65. package/shared/explorer-agent-display.test.ts +61 -0
  66. package/shared/explorer-agent-display.ts +21 -2
  67. package/shared/format.test.ts +28 -3
  68. package/shared/format.ts +25 -2
  69. package/shared/i18n.test.ts +34 -0
  70. package/shared/i18n.ts +363 -0
  71. package/shared/insights.test.ts +162 -80
  72. package/shared/insights.ts +136 -61
  73. package/shared/usage.test.ts +330 -0
  74. package/shared/usage.ts +471 -0
@@ -2,38 +2,34 @@ import { Icon } from "@getpaseo/plugin/client/react-native";
2
2
  import type { ReactNode } from "react";
3
3
  import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
4
  import { formatDisplayName } from "../../shared/format.ts";
5
- import type { McpByToolItem, SkillByNameItem } from "../../shared/usage.ts";
5
+ import type {
6
+ McpByToolItem,
7
+ RecentMcpCallItem,
8
+ RecentSkillCallItem,
9
+ SkillByNameItem,
10
+ } from "../../shared/usage.ts";
6
11
  import { FormattedTime } from "../formatted-time.tsx";
7
12
  import { RANK_ROW_ESTIMATE } from "./constants.ts";
13
+ import { ICON_SIZE } from "../design-tokens.ts";
14
+ import { useMessages } from "../use-app-language.ts";
15
+ import { CountText, IconButton, SectionHeader } from "../ui.tsx";
8
16
 
9
17
  type RankKind = "skills" | "mcp";
18
+ export type RankView = "ranked" | "timeline";
10
19
 
11
- function rankTitle(kind: RankKind): string {
12
- return kind === "skills" ? "Skills" : "MCP";
13
- }
14
-
15
- function rankAction(kind: RankKind): { icon: "Sparkles" | "Plug"; accessibilityLabel: string } {
16
- return kind === "skills"
17
- ? { icon: "Plug", accessibilityLabel: "Show most used MCP" }
18
- : { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
19
- }
20
-
21
- function CountText({
22
- value,
23
- styles,
24
- }: {
25
- value: number | string;
26
- styles: { countText: TextStyle };
27
- }): ReactNode {
28
- return <Text style={styles.countText}>{value}</Text>;
29
- }
30
20
 
31
21
  export type RankSectionStyles = {
22
+ section: ViewStyle;
32
23
  sectionHeaderRow: ViewStyle;
33
24
  sectionTitle: TextStyle;
34
25
  titleAction: ViewStyle;
26
+ headerActions: ViewStyle;
35
27
  panel: ViewStyle;
36
28
  listRow: ViewStyle;
29
+ timelineMarker: ViewStyle;
30
+ timelineLineTop: ViewStyle;
31
+ timelineLineBottom: ViewStyle;
32
+ timelineDot: ViewStyle;
37
33
  listMain: ViewStyle;
38
34
  listTitle: TextStyle;
39
35
  listMeta: TextStyle;
@@ -44,40 +40,71 @@ export type RankSectionStyles = {
44
40
  export function RankSection({
45
41
  rankKind,
46
42
  onToggleKind,
43
+ rankView,
44
+ onToggleRankView,
47
45
  showToggle = true,
48
46
  skillItems,
47
+ recentSkillCalls,
49
48
  mcpItems,
49
+ recentMcpCalls,
50
+ archivedAgentIds,
51
+ openAgent,
52
+ activeAgentColor,
53
+ archivedAgentColor,
50
54
  mutedColor,
55
+ activeTitleColor,
56
+ compact,
51
57
  styles,
52
58
  }: {
53
59
  rankKind: RankKind;
54
60
  onToggleKind: () => void;
61
+ rankView: RankView;
62
+ onToggleRankView: () => void;
55
63
  showToggle?: boolean;
56
64
  skillItems: ReadonlyArray<SkillByNameItem>;
65
+ recentSkillCalls: ReadonlyArray<RecentSkillCallItem>;
57
66
  mcpItems: ReadonlyArray<McpByToolItem>;
67
+ recentMcpCalls: ReadonlyArray<RecentMcpCallItem>;
68
+ archivedAgentIds: ReadonlySet<string>;
69
+ openAgent?: (input: { agentId: string }) => void;
70
+ activeAgentColor: string;
71
+ archivedAgentColor: string;
58
72
  mutedColor: string;
73
+ activeTitleColor: string;
74
+ compact: boolean;
59
75
  styles: RankSectionStyles;
60
76
  }): ReactNode {
77
+ const m = useMessages();
61
78
  if (skillItems.length === 0 && mcpItems.length === 0) return null;
79
+ const title = rankKind === "skills" ? m.common.skills : m.common.mcp;
62
80
 
63
- const items = rankKind === "skills" ? skillItems : mcpItems;
81
+ const items =
82
+ rankView === "timeline"
83
+ ? rankKind === "skills"
84
+ ? recentSkillCalls
85
+ : recentMcpCalls
86
+ : rankKind === "skills"
87
+ ? skillItems
88
+ : mcpItems;
64
89
 
65
90
  return (
66
- <View style={{ gap: 12 }}>
67
- <View style={styles.sectionHeaderRow}>
68
- <Text style={styles.sectionTitle}>{rankTitle(rankKind)}</Text>
91
+ <View style={styles.section}>
92
+ <SectionHeader title={title} colors={{ foreground: activeTitleColor, foregroundMuted: mutedColor }} compact={compact}>
69
93
  {showToggle ? (
70
- <Pressable
71
- accessibilityRole="button"
72
- accessibilityLabel={rankAction(rankKind).accessibilityLabel}
73
- hitSlop={8}
94
+ <IconButton
95
+ icon={rankKind === "skills" ? "Plug" : "Sparkles"}
96
+ label={rankKind === "skills" ? m.global.rankShow.mcp : m.global.rankShow.skills}
74
97
  onPress={onToggleKind}
75
- style={styles.titleAction}
76
- >
77
- <Icon name={rankAction(rankKind).icon} size={16} color={mutedColor} />
78
- </Pressable>
98
+ color={mutedColor}
99
+ />
79
100
  ) : null}
80
- </View>
101
+ <IconButton
102
+ icon={rankView === "ranked" ? "GitCommitVertical" : "LayoutList"}
103
+ label={rankView === "ranked" ? m.workspace.showTimeline(title) : m.workspace.showRanked(title)}
104
+ onPress={onToggleRankView}
105
+ color={mutedColor}
106
+ />
107
+ </SectionHeader>
81
108
  <View
82
109
  style={[
83
110
  styles.panel,
@@ -86,43 +113,129 @@ export function RankSection({
86
113
  },
87
114
  ]}
88
115
  >
89
- {rankKind === "skills"
90
- ? skillItems.map((item) => (
116
+ {rankKind === "skills" && rankView === "timeline"
117
+ ? recentSkillCalls.map((item, index) => {
118
+ const canOpen = openAgent != null && !archivedAgentIds.has(item.agentId);
119
+ return (
120
+ <Pressable
121
+ key={`${item.agentId}:${item.callId}`}
122
+ accessibilityRole={canOpen ? "link" : undefined}
123
+ accessibilityLabel={
124
+ canOpen ? m.common.openConversation(item.agentTitle ?? item.agentId) : undefined
125
+ }
126
+ accessibilityState={{ disabled: !canOpen }}
127
+ disabled={!canOpen}
128
+ onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
129
+ style={styles.listRow}
130
+ >
131
+ <View style={styles.timelineMarker}>
132
+ {index > 0 ? <View style={styles.timelineLineTop} /> : null}
133
+ <View
134
+ style={[
135
+ styles.timelineDot,
136
+ {
137
+ backgroundColor: archivedAgentIds.has(item.agentId)
138
+ ? archivedAgentColor
139
+ : activeAgentColor,
140
+ },
141
+ ]}
142
+ />
143
+ {index < recentSkillCalls.length - 1 ? (
144
+ <View style={styles.timelineLineBottom} />
145
+ ) : null}
146
+ </View>
147
+ <View style={styles.listMain}>
148
+ <Text style={styles.listTitle} numberOfLines={1}>
149
+ {formatDisplayName(item.skillName)}
150
+ </Text>
151
+ <Text style={styles.listMeta} numberOfLines={1}>
152
+ {item.agentTitle ?? item.agentId}
153
+ </Text>
154
+ </View>
155
+ <FormattedTime iso={item.calledAt} style={styles.listMeta} />
156
+ </Pressable>
157
+ );
158
+ })
159
+ : rankKind === "mcp" && rankView === "timeline"
160
+ ? recentMcpCalls.map((item, index) => {
161
+ const canOpen = openAgent != null && !archivedAgentIds.has(item.agentId);
162
+ return (
163
+ <Pressable
164
+ key={`${item.agentId}:${item.callId}`}
165
+ accessibilityRole={canOpen ? "link" : undefined}
166
+ accessibilityLabel={
167
+ canOpen ? m.common.openConversation(item.agentTitle ?? item.agentId) : undefined
168
+ }
169
+ accessibilityState={{ disabled: !canOpen }}
170
+ disabled={!canOpen}
171
+ onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
172
+ style={styles.listRow}
173
+ >
174
+ <View style={styles.timelineMarker}>
175
+ {index > 0 ? <View style={styles.timelineLineTop} /> : null}
176
+ <View
177
+ style={[
178
+ styles.timelineDot,
179
+ {
180
+ backgroundColor: archivedAgentIds.has(item.agentId)
181
+ ? archivedAgentColor
182
+ : activeAgentColor,
183
+ },
184
+ ]}
185
+ />
186
+ {index < recentMcpCalls.length - 1 ? (
187
+ <View style={styles.timelineLineBottom} />
188
+ ) : null}
189
+ </View>
190
+ <View style={styles.listMain}>
191
+ <Text style={styles.listTitle} numberOfLines={1}>
192
+ {formatDisplayName(`${item.server}.${item.tool}`)}
193
+ </Text>
194
+ <Text style={styles.listMeta} numberOfLines={1}>
195
+ {item.agentTitle ?? item.agentId}
196
+ </Text>
197
+ </View>
198
+ <FormattedTime iso={item.calledAt} style={styles.listMeta} />
199
+ </Pressable>
200
+ );
201
+ })
202
+ : rankKind === "skills"
203
+ ? skillItems.map((item) => (
91
204
  <View key={item.skillName} style={styles.listRow}>
92
- <Icon name="Sparkles" size={18} color={mutedColor} />
205
+ <Icon name="Sparkles" size={ICON_SIZE.leading} color={mutedColor} />
93
206
  <View style={styles.listMain}>
94
207
  <Text style={styles.listTitle} numberOfLines={1}>
95
208
  {formatDisplayName(item.skillName)}
96
209
  </Text>
97
210
  <FormattedTime
98
211
  iso={item.lastUsedAt}
99
- prefix="Last "
212
+ format={m.common.lastUsed}
100
213
  style={styles.listMeta}
101
214
  />
102
215
  </View>
103
- <CountText value={item.total} styles={styles} />
216
+ <CountText value={item.total} color={mutedColor} />
104
217
  </View>
105
- ))
106
- : mcpItems.map((item) => (
218
+ ))
219
+ : mcpItems.map((item) => (
107
220
  <View key={`${item.server}.${item.tool}`} style={styles.listRow}>
108
- <Icon name="Plug" size={18} color={mutedColor} />
221
+ <Icon name="Plug" size={ICON_SIZE.leading} color={mutedColor} />
109
222
  <View style={styles.listMain}>
110
223
  <Text style={styles.listTitle} numberOfLines={1}>
111
224
  {formatDisplayName(`${item.server}.${item.tool}`)}
112
225
  </Text>
113
226
  {item.failures > 0 ? (
114
- <Text style={styles.listMeta}>{item.failures} failed</Text>
227
+ <Text style={styles.listMeta}>{m.common.failed(item.failures)}</Text>
115
228
  ) : item.lastUsedAt ? (
116
229
  <FormattedTime
117
230
  iso={item.lastUsedAt}
118
- prefix="Last "
231
+ format={m.common.lastUsed}
119
232
  style={styles.listMeta}
120
233
  />
121
234
  ) : (
122
235
  <Text style={styles.listMeta}>—</Text>
123
236
  )}
124
237
  </View>
125
- <CountText value={item.count} styles={styles} />
238
+ <CountText value={item.count} color={mutedColor} />
126
239
  </View>
127
240
  ))}
128
241
  </View>
@@ -14,6 +14,8 @@ import {
14
14
  import { collapseHomePath } from "../../shared/home-path.ts";
15
15
  import { TERMINAL_PREVIEW_LINES, TERMINAL_REFETCH_MS } from "./constants.ts";
16
16
  import { terminalPreviewLines } from "./terminal-preview.ts";
17
+ import { CONTROL, ICON_SIZE } from "../design-tokens.ts";
18
+ import { useMessages } from "../use-app-language.ts";
17
19
 
18
20
  export type TerminalListItem = {
19
21
  id: string;
@@ -23,6 +25,7 @@ export type TerminalListItem = {
23
25
  };
24
26
 
25
27
  export type TerminalsSectionStyles = {
28
+ section: ViewStyle;
26
29
  sectionHeaderRow: ViewStyle;
27
30
  sectionTitle: TextStyle;
28
31
  panel: ViewStyle;
@@ -52,6 +55,7 @@ export function TerminalsSection({
52
55
  styles: TerminalsSectionStyles;
53
56
  onClose: (item: TerminalListItem) => void;
54
57
  }): ReactNode {
58
+ const m = useMessages();
55
59
  const paseo = usePaseo();
56
60
  const [expandedId, setExpandedId] = useState<string | null>(null);
57
61
  const [hoveredId, setHoveredId] = useState<string | null>(null);
@@ -76,9 +80,9 @@ export function TerminalsSection({
76
80
  });
77
81
 
78
82
  return (
79
- <View style={{ gap: 12 }}>
83
+ <View style={styles.section}>
80
84
  <View style={styles.sectionHeaderRow}>
81
- <Text style={styles.sectionTitle}>Terminals</Text>
85
+ <Text style={styles.sectionTitle}>{m.workspace.terminals}</Text>
82
86
  </View>
83
87
  <View style={styles.panel}>
84
88
  {terminalItems.map((item) => {
@@ -92,7 +96,7 @@ export function TerminalsSection({
92
96
  <Pressable
93
97
  accessibilityRole="button"
94
98
  accessibilityLabel={
95
- expanded ? `Hide output of ${item.name}` : `Show output of ${item.name}`
99
+ expanded ? m.workspace.hideOutput(item.name) : m.workspace.showOutput(item.name)
96
100
  }
97
101
  accessibilityState={{ expanded }}
98
102
  onPress={() => setExpandedId(expanded ? null : item.id)}
@@ -105,7 +109,7 @@ export function TerminalsSection({
105
109
  } as object)
106
110
  : null)}
107
111
  >
108
- <Icon name="Terminal" size={18} color={mutedColor} />
112
+ <Icon name="Terminal" size={ICON_SIZE.leading} color={mutedColor} />
109
113
  <View style={styles.listMain}>
110
114
  <Text style={styles.listTitle} numberOfLines={1}>
111
115
  {item.name}
@@ -116,10 +120,10 @@ export function TerminalsSection({
116
120
  </View>
117
121
  <Pressable
118
122
  accessibilityRole="button"
119
- accessibilityLabel={`Close ${item.name}`}
123
+ accessibilityLabel={m.workspace.closeTerminal(item.name)}
120
124
  accessibilityState={{ disabled: busyTerminalId != null }}
121
125
  disabled={busyTerminalId != null || !showClose}
122
- hitSlop={8}
126
+ hitSlop={CONTROL.hitSlop}
123
127
  onPress={() => onClose(item)}
124
128
  pointerEvents={showClose ? "auto" : "none"}
125
129
  style={[styles.titleAction, { opacity: showClose ? 1 : 0 }]}
@@ -127,16 +131,16 @@ export function TerminalsSection({
127
131
  {busy ? (
128
132
  <ActivityIndicator size="small" color={mutedColor} />
129
133
  ) : (
130
- <Icon name="X" size={14} color={mutedColor} />
134
+ <Icon name="X" size={ICON_SIZE.inline} color={mutedColor} />
131
135
  )}
132
136
  </Pressable>
133
137
  </Pressable>
134
138
  {expanded ? (
135
139
  <View style={styles.terminalPreview}>
136
140
  {capture.isPending ? (
137
- <Text style={styles.listMeta}>Loading…</Text>
141
+ <Text style={styles.listMeta}>{m.common.loading}</Text>
138
142
  ) : lines.length === 0 ? (
139
- <Text style={styles.listMeta}>No output</Text>
143
+ <Text style={styles.listMeta}>{m.workspace.noOutput}</Text>
140
144
  ) : (
141
145
  lines.map((line, index) => (
142
146
  <Text key={index} style={styles.terminalLine} numberOfLines={1}>
package/index.client.tsx CHANGED
@@ -2,11 +2,43 @@ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
2
  import { GlobalUsageSurface } from "./client/global-surface.tsx";
3
3
  import { UsagePanel } from "./client/panel.tsx";
4
4
  import { contributeAttentionPills } from "./client/attention-pill.tsx";
5
+ import { contributeHeaderButtons } from "./client/header-button.ts";
5
6
  import { contributePills } from "./client/pill.tsx";
6
7
  import { WorkspaceActivityPanel } from "./client/workspace-panel.tsx";
8
+ import { currentAppLanguage, watchAppLanguage } from "./client/use-app-language.ts";
9
+ import { messagesFor } from "./shared/i18n.ts";
7
10
 
8
11
  const GLOBAL_SURFACE_ID = "activity";
9
12
 
13
+ /** Command titles follow the app language; the host has no update(), so re-register on change. */
14
+ function addScopedCommands(client: PluginClientContext): () => void {
15
+ const { commands } = messagesFor(currentAppLanguage());
16
+ const removeAgent = client.addCommandCenterItem({
17
+ id: "open-usage",
18
+ title: commands.agentActivity,
19
+ icon: "Activity",
20
+ keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
21
+ context: "agent",
22
+ onSelect: ({ openPanel }) => {
23
+ openPanel("usage");
24
+ },
25
+ });
26
+ const removeWorkspace = client.addCommandCenterItem({
27
+ id: "open-workspace-activity",
28
+ title: commands.workspaceActivity,
29
+ icon: "Activity",
30
+ keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
31
+ context: "workspace",
32
+ onSelect({ openPanel }) {
33
+ openPanel("workspace-activity", { location: "explorer" });
34
+ },
35
+ });
36
+ return () => {
37
+ removeAgent();
38
+ removeWorkspace();
39
+ };
40
+ }
41
+
10
42
  export default function contribute(client: PluginClientContext) {
11
43
  client.addSurface(GLOBAL_SURFACE_ID, GlobalUsageSurface);
12
44
  client.addSidebarItem({
@@ -44,32 +76,20 @@ export default function contribute(client: PluginClientContext) {
44
76
  },
45
77
  });
46
78
 
47
- client.addCommandCenterItem({
48
- id: "open-usage",
49
- title: "Agent Activity",
50
- icon: "Activity",
51
- keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
52
- context: "agent",
53
- onSelect: ({ openPanel }) => {
54
- openPanel("usage");
55
- },
56
- });
57
-
58
- client.addCommandCenterItem({
59
- id: "open-workspace-activity",
60
- title: "Workspace Activity",
61
- icon: "Activity",
62
- keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
63
- context: "workspace",
64
- onSelect({ openPanel }) {
65
- openPanel("workspace-activity", { location: "explorer" });
66
- },
79
+ let removeScopedCommands = addScopedCommands(client);
80
+ const stopLanguage = watchAppLanguage(() => {
81
+ removeScopedCommands();
82
+ removeScopedCommands = addScopedCommands(client);
67
83
  });
68
84
 
69
85
  const stopUsagePills = contributePills(client);
70
86
  const stopAttentionPills = contributeAttentionPills(client);
87
+ const stopHeaderButtons = contributeHeaderButtons(client);
71
88
  return () => {
89
+ stopLanguage();
90
+ removeScopedCommands();
72
91
  stopUsagePills();
73
92
  stopAttentionPills();
93
+ stopHeaderButtons();
74
94
  };
75
95
  }
package/index.server.ts CHANGED
@@ -1,14 +1,20 @@
1
1
  import { createBackgroundSync } from "./server/background-sync.ts";
2
2
  import { homedir } from "node:os";
3
- import type { PluginServerContext } from "@getpaseo/plugin/server";
3
+ import type { PluginHandlerContext, PluginServerContext } from "@getpaseo/plugin/server";
4
4
  import {
5
+ createActivityByHourHandler,
5
6
  createActivityByDayHandler,
7
+ createAgentCreationsHandler,
8
+ createAgentLifetimeHandler,
6
9
  createAgentsHandler,
10
+ createByProjectHandler,
7
11
  createByProviderHandler,
8
12
  createExportHandler,
9
13
  createListHandler,
10
14
  createMcpByToolHandler,
11
15
  createReadSkillHandler,
16
+ createRecentMcpCallsHandler,
17
+ createRecentSkillCallsHandler,
12
18
  createSkillsByNameHandler,
13
19
  createSummaryHandler,
14
20
  createUnarchiveAgentHandler,
@@ -16,17 +22,24 @@ import {
16
22
  import { agentRowFromHook } from "./server/agents.ts";
17
23
  import { ingestTimeline, ingestUserMessages } from "./server/ingest.ts";
18
24
  import { resolveAgentModel } from "./server/resolve-model.ts";
25
+ import { createRpcCache } from "./server/rpc-cache.ts";
19
26
  import { createUsageStore } from "./server/store.ts";
20
27
  import {
28
+ usageActivityByHourRpc,
21
29
  usageActivityByDayRpc,
30
+ usageAgentCreationsRpc,
31
+ usageAgentLifetimeRpc,
22
32
  usageAgentsRpc,
23
33
  usageAgentUnarchiveRpc,
34
+ usageByProjectRpc,
24
35
  usageByProviderRpc,
25
36
  usageExportRpc,
26
37
  usageHostInfoRpc,
27
38
  usageListRpc,
28
39
  usageMcpByToolRpc,
29
40
  usageReadSkillRpc,
41
+ usageRecentMcpCallsRpc,
42
+ usageRecentSkillCallsRpc,
30
43
  usageSkillsByNameRpc,
31
44
  usageSummaryRpc,
32
45
  } from "./shared/usage.ts";
@@ -35,38 +48,51 @@ import { explorerAgentDisplaySettings } from "./shared/explorer-agent-display.ts
35
48
  export default function contribute(server: PluginServerContext) {
36
49
  const store = createUsageStore();
37
50
  const background = createBackgroundSync(store);
51
+ const cache = createRpcCache({ generation: () => store.generation() });
38
52
  console.log(`[activity] store ready (driver=${store.driver})`);
39
53
  server.registerSettings(explorerAgentDisplaySettings);
40
54
 
41
- server.handle(usageSummaryRpc, (input, context) => {
42
- void background.request(context.paseo);
43
- return createSummaryHandler(store)(input);
44
- });
45
- server.handle(usageListRpc, (input, context) => {
46
- void background.request(context.paseo);
47
- return createListHandler(store)(input);
48
- });
49
- server.handle(usageSkillsByNameRpc, (input, context) => {
50
- void background.request(context.paseo);
51
- return createSkillsByNameHandler(store)(input, context);
52
- });
53
- server.handle(usageMcpByToolRpc, (input, context) => {
54
- void background.request(context.paseo);
55
- return createMcpByToolHandler(store)(input);
56
- });
57
- server.handle(usageByProviderRpc, (input, context) => {
58
- void background.request(context.paseo);
59
- return createByProviderHandler(store)(input);
60
- });
61
- server.handle(usageAgentsRpc, (input, context) => {
62
- void background.request(context.paseo);
63
- return createAgentsHandler(store)(input);
64
- });
55
+ /** Cached read RPC that also nudges the background history check. */
56
+ function read<I, O>(
57
+ rpc: { name: string },
58
+ handler: (input: I, context: PluginHandlerContext) => Promise<O>,
59
+ ) {
60
+ const cached = cache.wrap(rpc.name, handler);
61
+ return (input: I, context: PluginHandlerContext) => {
62
+ void background.request(context.paseo);
63
+ return cached(input, context);
64
+ };
65
+ }
66
+
67
+ server.handle(usageSummaryRpc, read(usageSummaryRpc, createSummaryHandler(store)));
68
+ server.handle(usageListRpc, read(usageListRpc, createListHandler(store)));
69
+ server.handle(usageSkillsByNameRpc, read(usageSkillsByNameRpc, createSkillsByNameHandler(store)));
70
+ server.handle(
71
+ usageRecentSkillCallsRpc,
72
+ read(usageRecentSkillCallsRpc, createRecentSkillCallsHandler(store)),
73
+ );
74
+ server.handle(
75
+ usageRecentMcpCallsRpc,
76
+ read(usageRecentMcpCallsRpc, createRecentMcpCallsHandler(store)),
77
+ );
78
+ server.handle(usageMcpByToolRpc, read(usageMcpByToolRpc, createMcpByToolHandler(store)));
79
+ server.handle(usageByProviderRpc, read(usageByProviderRpc, createByProviderHandler(store)));
80
+ server.handle(usageByProjectRpc, read(usageByProjectRpc, createByProjectHandler(store)));
81
+ server.handle(usageAgentsRpc, read(usageAgentsRpc, createAgentsHandler(store)));
65
82
  server.handle(usageAgentUnarchiveRpc, createUnarchiveAgentHandler(store));
66
- server.handle(usageActivityByDayRpc, (input, context) => {
67
- void background.request(context.paseo);
68
- return createActivityByDayHandler(store)(input);
69
- });
83
+ server.handle(usageActivityByDayRpc, read(usageActivityByDayRpc, createActivityByDayHandler(store)));
84
+ server.handle(
85
+ usageActivityByHourRpc,
86
+ read(usageActivityByHourRpc, createActivityByHourHandler(store)),
87
+ );
88
+ server.handle(
89
+ usageAgentLifetimeRpc,
90
+ read(usageAgentLifetimeRpc, createAgentLifetimeHandler(store)),
91
+ );
92
+ server.handle(
93
+ usageAgentCreationsRpc,
94
+ read(usageAgentCreationsRpc, createAgentCreationsHandler(store)),
95
+ );
70
96
  server.handle(usageExportRpc, createExportHandler(store));
71
97
  server.handle(usageHostInfoRpc, () => ({ homeDir: homedir() }));
72
98
  server.handle(usageReadSkillRpc, createReadSkillHandler());
@@ -111,8 +137,14 @@ export default function contribute(server: PluginServerContext) {
111
137
  store.upsertUserMessages(
112
138
  ingestUserMessages(event.timeline, event.agent, { model }),
113
139
  );
114
- // mcpServers resolved inside ingestTimeline (OpenCode config + paseo inject + agent persistence)
115
- const rows = ingestTimeline(event.timeline, event.agent, null, {
140
+ store.pruneReplayDuplicateMessages(event.agent.id);
141
+ // event.timeline is the whole history; calls already stored in a terminal
142
+ // status cannot change from a live snapshot, so only the rest are upserted.
143
+ const settled = store.terminalCallIds(event.agent.id);
144
+ const pending = event.timeline.filter(
145
+ (item) => item.type !== "tool_call" || !settled.has(item.callId),
146
+ );
147
+ const rows = ingestTimeline(pending, event.agent, null, {
116
148
  homeDir: homedir(),
117
149
  });
118
150
  if (rows.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koinzhang/paseo-plugin-activity",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Local usage analytics and workspace agent ops for Paseo: tools, agents, messages, models, Explorer fleet list, and terminals.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "typecheck": "tsc --noEmit",
25
- "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/workspace/list-host-agents.test.ts client/agent-directory.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/provider-filter.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts"
25
+ "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/agent-directory.test.ts client/workspace/list-host-agents.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/color-mix.test.ts client/design-tokens.test.ts client/fit-text.test.ts client/provider-filter.test.ts client/range.test.ts client/panel-visibility.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/i18n.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/explorer-agent-display.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts server/rpc-cache.test.ts"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@getpaseo/plugin": "0.9.0-beta.2",
package/paseo-plugin.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "id": "activity",
3
+ "description": "Local usage analytics and workspace agent ops: Explorer fleet list, live attention, and terminals",
3
4
  "requirements": {
4
- "paseo": ">=0.9.0-beta.2"
5
+ "paseo": ">=0.9.0"
5
6
  }
6
7
  }