@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,4 +1,4 @@
1
- import { Icon } from "@getpaseo/plugin/client/react-native";
1
+ import { Icon } from "@getpaseo/plugin/client/ui";
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";
@@ -10,37 +10,23 @@ import type {
10
10
  } from "../../shared/usage.ts";
11
11
  import { FormattedTime } from "../formatted-time.tsx";
12
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";
13
16
 
14
17
  type RankKind = "skills" | "mcp";
15
18
  export type RankView = "ranked" | "timeline";
16
19
 
17
- function rankTitle(kind: RankKind): string {
18
- return kind === "skills" ? "Skills" : "MCP";
19
- }
20
-
21
- function rankAction(kind: RankKind): { icon: "Sparkles" | "Plug"; accessibilityLabel: string } {
22
- return kind === "skills"
23
- ? { icon: "Plug", accessibilityLabel: "Show most used MCP" }
24
- : { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
25
- }
26
-
27
- function CountText({
28
- value,
29
- styles,
30
- }: {
31
- value: number | string;
32
- styles: { countText: TextStyle };
33
- }): ReactNode {
34
- return <Text style={styles.countText}>{value}</Text>;
35
- }
36
20
 
37
21
  export type RankSectionStyles = {
22
+ section: ViewStyle;
38
23
  sectionHeaderRow: ViewStyle;
39
24
  sectionTitle: TextStyle;
40
25
  titleAction: ViewStyle;
41
26
  headerActions: ViewStyle;
42
27
  panel: ViewStyle;
43
28
  listRow: ViewStyle;
29
+ listRowPressed: ViewStyle;
44
30
  timelineMarker: ViewStyle;
45
31
  timelineLineTop: ViewStyle;
46
32
  timelineLineBottom: ViewStyle;
@@ -67,6 +53,8 @@ export function RankSection({
67
53
  activeAgentColor,
68
54
  archivedAgentColor,
69
55
  mutedColor,
56
+ activeTitleColor,
57
+ compact,
70
58
  styles,
71
59
  }: {
72
60
  rankKind: RankKind;
@@ -83,9 +71,13 @@ export function RankSection({
83
71
  activeAgentColor: string;
84
72
  archivedAgentColor: string;
85
73
  mutedColor: string;
74
+ activeTitleColor: string;
75
+ compact: boolean;
86
76
  styles: RankSectionStyles;
87
77
  }): ReactNode {
78
+ const m = useMessages();
88
79
  if (skillItems.length === 0 && mcpItems.length === 0) return null;
80
+ const title = rankKind === "skills" ? m.common.skills : m.common.mcp;
89
81
 
90
82
  const items =
91
83
  rankView === "timeline"
@@ -97,40 +89,23 @@ export function RankSection({
97
89
  : mcpItems;
98
90
 
99
91
  return (
100
- <View style={{ gap: 12 }}>
101
- <View style={styles.sectionHeaderRow}>
102
- <Text style={styles.sectionTitle}>{rankTitle(rankKind)}</Text>
103
- <View style={styles.headerActions}>
104
- {showToggle ? (
105
- <Pressable
106
- accessibilityRole="button"
107
- accessibilityLabel={rankAction(rankKind).accessibilityLabel}
108
- hitSlop={8}
109
- onPress={onToggleKind}
110
- style={styles.titleAction}
111
- >
112
- <Icon name={rankAction(rankKind).icon} size={16} color={mutedColor} />
113
- </Pressable>
114
- ) : null}
115
- <Pressable
116
- accessibilityRole="button"
117
- accessibilityLabel={
118
- rankView === "ranked"
119
- ? `Show ${rankTitle(rankKind)} as a timeline`
120
- : `Show ${rankTitle(rankKind)} ranked by calls`
121
- }
122
- hitSlop={8}
123
- onPress={onToggleRankView}
124
- style={styles.titleAction}
125
- >
126
- <Icon
127
- name={rankView === "ranked" ? "GitCommitVertical" : "LayoutList"}
128
- size={16}
129
- color={mutedColor}
130
- />
131
- </Pressable>
132
- </View>
133
- </View>
92
+ <View style={styles.section}>
93
+ <SectionHeader title={title} colors={{ foreground: activeTitleColor, foregroundMuted: mutedColor }} compact={compact}>
94
+ {showToggle ? (
95
+ <IconButton
96
+ icon={rankKind === "skills" ? "Plug" : "Sparkles"}
97
+ label={rankKind === "skills" ? m.global.rankShow.mcp : m.global.rankShow.skills}
98
+ onPress={onToggleKind}
99
+ color={mutedColor}
100
+ />
101
+ ) : null}
102
+ <IconButton
103
+ icon={rankView === "ranked" ? "GitCommitVertical" : "LayoutList"}
104
+ label={rankView === "ranked" ? m.workspace.showTimeline(title) : m.workspace.showRanked(title)}
105
+ onPress={onToggleRankView}
106
+ color={mutedColor}
107
+ />
108
+ </SectionHeader>
134
109
  <View
135
110
  style={[
136
111
  styles.panel,
@@ -147,12 +122,12 @@ export function RankSection({
147
122
  key={`${item.agentId}:${item.callId}`}
148
123
  accessibilityRole={canOpen ? "link" : undefined}
149
124
  accessibilityLabel={
150
- canOpen ? `Open conversation ${item.agentTitle ?? item.agentId}` : undefined
125
+ canOpen ? m.common.openConversation(item.agentTitle ?? item.agentId) : undefined
151
126
  }
152
127
  accessibilityState={{ disabled: !canOpen }}
153
128
  disabled={!canOpen}
154
129
  onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
155
- style={styles.listRow}
130
+ style={({ pressed }) => [styles.listRow, pressed ? styles.listRowPressed : null]}
156
131
  >
157
132
  <View style={styles.timelineMarker}>
158
133
  {index > 0 ? <View style={styles.timelineLineTop} /> : null}
@@ -190,12 +165,12 @@ export function RankSection({
190
165
  key={`${item.agentId}:${item.callId}`}
191
166
  accessibilityRole={canOpen ? "link" : undefined}
192
167
  accessibilityLabel={
193
- canOpen ? `Open conversation ${item.agentTitle ?? item.agentId}` : undefined
168
+ canOpen ? m.common.openConversation(item.agentTitle ?? item.agentId) : undefined
194
169
  }
195
170
  accessibilityState={{ disabled: !canOpen }}
196
171
  disabled={!canOpen}
197
172
  onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
198
- style={styles.listRow}
173
+ style={({ pressed }) => [styles.listRow, pressed ? styles.listRowPressed : null]}
199
174
  >
200
175
  <View style={styles.timelineMarker}>
201
176
  {index > 0 ? <View style={styles.timelineLineTop} /> : null}
@@ -228,40 +203,40 @@ export function RankSection({
228
203
  : rankKind === "skills"
229
204
  ? skillItems.map((item) => (
230
205
  <View key={item.skillName} style={styles.listRow}>
231
- <Icon name="Sparkles" size={18} color={mutedColor} />
206
+ <Icon name="Sparkles" size={ICON_SIZE.leading} color={mutedColor} />
232
207
  <View style={styles.listMain}>
233
208
  <Text style={styles.listTitle} numberOfLines={1}>
234
209
  {formatDisplayName(item.skillName)}
235
210
  </Text>
236
211
  <FormattedTime
237
212
  iso={item.lastUsedAt}
238
- prefix="Last "
213
+ format={m.common.lastUsed}
239
214
  style={styles.listMeta}
240
215
  />
241
216
  </View>
242
- <CountText value={item.total} styles={styles} />
217
+ <CountText value={item.total} color={mutedColor} />
243
218
  </View>
244
219
  ))
245
220
  : mcpItems.map((item) => (
246
221
  <View key={`${item.server}.${item.tool}`} style={styles.listRow}>
247
- <Icon name="Plug" size={18} color={mutedColor} />
222
+ <Icon name="Plug" size={ICON_SIZE.leading} color={mutedColor} />
248
223
  <View style={styles.listMain}>
249
224
  <Text style={styles.listTitle} numberOfLines={1}>
250
225
  {formatDisplayName(`${item.server}.${item.tool}`)}
251
226
  </Text>
252
227
  {item.failures > 0 ? (
253
- <Text style={styles.listMeta}>{item.failures} failed</Text>
228
+ <Text style={styles.listMeta}>{m.common.failed(item.failures)}</Text>
254
229
  ) : item.lastUsedAt ? (
255
230
  <FormattedTime
256
231
  iso={item.lastUsedAt}
257
- prefix="Last "
232
+ format={m.common.lastUsed}
258
233
  style={styles.listMeta}
259
234
  />
260
235
  ) : (
261
236
  <Text style={styles.listMeta}>—</Text>
262
237
  )}
263
238
  </View>
264
- <CountText value={item.count} styles={styles} />
239
+ <CountText value={item.count} color={mutedColor} />
265
240
  </View>
266
241
  ))}
267
242
  </View>
@@ -21,7 +21,7 @@ export function RunningIndicator({
21
21
  toValue: 1,
22
22
  duration: SPIN_DURATION_MS,
23
23
  easing: Easing.linear,
24
- useNativeDriver: false,
24
+ useNativeDriver: true,
25
25
  }),
26
26
  );
27
27
  animation.start();
@@ -1,5 +1,5 @@
1
1
  import { usePaseo } from "@getpaseo/plugin/client";
2
- import { Icon } from "@getpaseo/plugin/client/react-native";
2
+ import { Icon } from "@getpaseo/plugin/client/ui";
3
3
  import { useQuery } from "@tanstack/react-query";
4
4
  import { useEffect, useState, type ReactNode } from "react";
5
5
  import {
@@ -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, PRESS } from "../design-tokens.ts";
18
+ import { useMessages } from "../use-app-language.ts";
17
19
 
18
20
  export type TerminalListItem = {
19
21
  id: string;
@@ -23,10 +25,12 @@ 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;
29
32
  terminalRow: ViewStyle;
33
+ terminalRowPressed: ViewStyle;
30
34
  listMain: ViewStyle;
31
35
  listTitle: TextStyle;
32
36
  listMeta: TextStyle;
@@ -52,6 +56,7 @@ export function TerminalsSection({
52
56
  styles: TerminalsSectionStyles;
53
57
  onClose: (item: TerminalListItem) => void;
54
58
  }): ReactNode {
59
+ const m = useMessages();
55
60
  const paseo = usePaseo();
56
61
  const [expandedId, setExpandedId] = useState<string | null>(null);
57
62
  const [hoveredId, setHoveredId] = useState<string | null>(null);
@@ -76,9 +81,9 @@ export function TerminalsSection({
76
81
  });
77
82
 
78
83
  return (
79
- <View style={{ gap: 12 }}>
84
+ <View style={styles.section}>
80
85
  <View style={styles.sectionHeaderRow}>
81
- <Text style={styles.sectionTitle}>Terminals</Text>
86
+ <Text style={styles.sectionTitle}>{m.workspace.terminals}</Text>
82
87
  </View>
83
88
  <View style={styles.panel}>
84
89
  {terminalItems.map((item) => {
@@ -92,11 +97,14 @@ export function TerminalsSection({
92
97
  <Pressable
93
98
  accessibilityRole="button"
94
99
  accessibilityLabel={
95
- expanded ? `Hide output of ${item.name}` : `Show output of ${item.name}`
100
+ expanded ? m.workspace.hideOutput(item.name) : m.workspace.showOutput(item.name)
96
101
  }
97
102
  accessibilityState={{ expanded }}
98
103
  onPress={() => setExpandedId(expanded ? null : item.id)}
99
- style={styles.terminalRow}
104
+ style={({ pressed }) => [
105
+ styles.terminalRow,
106
+ pressed ? styles.terminalRowPressed : null,
107
+ ]}
100
108
  {...(Platform.OS === "web"
101
109
  ? ({
102
110
  onMouseEnter: () => setHoveredId(item.id),
@@ -105,7 +113,7 @@ export function TerminalsSection({
105
113
  } as object)
106
114
  : null)}
107
115
  >
108
- <Icon name="Terminal" size={18} color={mutedColor} />
116
+ <Icon name="Terminal" size={ICON_SIZE.leading} color={mutedColor} />
109
117
  <View style={styles.listMain}>
110
118
  <Text style={styles.listTitle} numberOfLines={1}>
111
119
  {item.name}
@@ -116,27 +124,31 @@ export function TerminalsSection({
116
124
  </View>
117
125
  <Pressable
118
126
  accessibilityRole="button"
119
- accessibilityLabel={`Close ${item.name}`}
127
+ accessibilityLabel={m.workspace.closeTerminal(item.name)}
120
128
  accessibilityState={{ disabled: busyTerminalId != null }}
121
129
  disabled={busyTerminalId != null || !showClose}
122
- hitSlop={8}
130
+ hitSlop={CONTROL.hitSlop}
123
131
  onPress={() => onClose(item)}
124
132
  pointerEvents={showClose ? "auto" : "none"}
125
- style={[styles.titleAction, { opacity: showClose ? 1 : 0 }]}
133
+ style={({ pressed }) => [
134
+ styles.titleAction,
135
+ { opacity: showClose ? 1 : 0 },
136
+ pressed ? { opacity: PRESS.opacity, transform: [{ scale: PRESS.scale }] } : null,
137
+ ]}
126
138
  >
127
139
  {busy ? (
128
140
  <ActivityIndicator size="small" color={mutedColor} />
129
141
  ) : (
130
- <Icon name="X" size={14} color={mutedColor} />
142
+ <Icon name="X" size={ICON_SIZE.inline} color={mutedColor} />
131
143
  )}
132
144
  </Pressable>
133
145
  </Pressable>
134
146
  {expanded ? (
135
147
  <View style={styles.terminalPreview}>
136
148
  {capture.isPending ? (
137
- <Text style={styles.listMeta}>Loading…</Text>
149
+ <Text style={styles.listMeta}>{m.common.loading}</Text>
138
150
  ) : lines.length === 0 ? (
139
- <Text style={styles.listMeta}>No output</Text>
151
+ <Text style={styles.listMeta}>{m.workspace.noOutput}</Text>
140
152
  ) : (
141
153
  lines.map((line, index) => (
142
154
  <Text key={index} style={styles.terminalLine} numberOfLines={1}>
package/index.client.tsx CHANGED
@@ -2,25 +2,60 @@ 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";
7
+ import { ACTIVITY_SCREEN_ID, ActivitySidebarItem } from "./client/sidebar-item.tsx";
6
8
  import { WorkspaceActivityPanel } from "./client/workspace-panel.tsx";
9
+ import { currentAppLanguage, watchAppLanguage } from "./client/use-app-language.ts";
10
+ import { messagesFor } from "./shared/i18n.ts";
7
11
 
8
- const GLOBAL_SURFACE_ID = "activity";
12
+ const GLOBAL_SCREEN_ID = ACTIVITY_SCREEN_ID;
13
+
14
+ /** Command titles follow the app language; the host has no update(), so re-register on change. */
15
+ function addScopedCommands(client: PluginClientContext): () => void {
16
+ const { commands } = messagesFor(currentAppLanguage());
17
+ const removeAgent = client.addCommandCenterItem({
18
+ id: "open-usage",
19
+ title: commands.agentActivity,
20
+ icon: "Activity",
21
+ keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
22
+ context: "agent",
23
+ onSelect: ({ openPanel }) => {
24
+ openPanel("usage");
25
+ },
26
+ });
27
+ const removeWorkspace = client.addCommandCenterItem({
28
+ id: "open-workspace-activity",
29
+ title: commands.workspaceActivity,
30
+ icon: "Activity",
31
+ keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
32
+ context: "workspace",
33
+ onSelect({ openPanel }) {
34
+ openPanel("workspace-activity", { location: "explorer" });
35
+ },
36
+ });
37
+ return () => {
38
+ removeAgent();
39
+ removeWorkspace();
40
+ };
41
+ }
9
42
 
10
43
  export default function contribute(client: PluginClientContext) {
11
- client.addSurface(GLOBAL_SURFACE_ID, GlobalUsageSurface);
12
- client.addSidebarItem({
13
- id: "activity",
44
+ client.addScreen({
45
+ id: GLOBAL_SCREEN_ID,
14
46
  title: "Activity",
15
- icon: "Activity",
16
- surface: GLOBAL_SURFACE_ID,
47
+ Component: GlobalUsageSurface,
48
+ });
49
+ client.addSidebarHeaderItem({
50
+ id: GLOBAL_SCREEN_ID,
51
+ title: "Activity",
52
+ Component: ActivitySidebarItem,
17
53
  });
18
54
 
19
- client.addWorkspacePanel({
55
+ client.addAgentPanel({
20
56
  id: "usage",
21
57
  title: "Activity",
22
58
  icon: "Activity",
23
- context: "agent",
24
59
  Component: UsagePanel,
25
60
  });
26
61
 
@@ -28,7 +63,6 @@ export default function contribute(client: PluginClientContext) {
28
63
  id: "workspace-activity",
29
64
  title: "Activity",
30
65
  icon: "Activity",
31
- context: "workspace",
32
66
  locations: ["explorer"],
33
67
  Component: WorkspaceActivityPanel,
34
68
  });
@@ -39,37 +73,25 @@ export default function contribute(client: PluginClientContext) {
39
73
  icon: "Activity",
40
74
  keywords: ["activity", "tool", "usage", "provider", "all", "global", "sidebar"],
41
75
  context: "global",
42
- onSelect({ openSurface }) {
43
- openSurface(GLOBAL_SURFACE_ID);
44
- },
45
- });
46
-
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");
76
+ onSelect({ openScreen }) {
77
+ openScreen({ screenId: GLOBAL_SCREEN_ID });
55
78
  },
56
79
  });
57
80
 
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
- },
81
+ let removeScopedCommands = addScopedCommands(client);
82
+ const stopLanguage = watchAppLanguage(() => {
83
+ removeScopedCommands();
84
+ removeScopedCommands = addScopedCommands(client);
67
85
  });
68
86
 
69
87
  const stopUsagePills = contributePills(client);
70
88
  const stopAttentionPills = contributeAttentionPills(client);
89
+ const stopHeaderButtons = contributeHeaderButtons(client);
71
90
  return () => {
91
+ stopLanguage();
92
+ removeScopedCommands();
72
93
  stopUsagePills();
73
94
  stopAttentionPills();
95
+ stopHeaderButtons();
74
96
  };
75
97
  }
package/index.server.ts CHANGED
@@ -1,12 +1,13 @@
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
5
  createActivityByHourHandler,
6
6
  createActivityByDayHandler,
7
7
  createAgentCreationsHandler,
8
8
  createAgentLifetimeHandler,
9
9
  createAgentsHandler,
10
+ createByProjectHandler,
10
11
  createByProviderHandler,
11
12
  createExportHandler,
12
13
  createListHandler,
@@ -19,9 +20,9 @@ import {
19
20
  createUnarchiveAgentHandler,
20
21
  } from "./server/handlers.ts";
21
22
  import { agentRowFromHook } from "./server/agents.ts";
22
- import { ingestTimeline, ingestUserMessages } from "./server/ingest.ts";
23
- import { resolveAgentModel } from "./server/resolve-model.ts";
23
+ import { createRpcCache } from "./server/rpc-cache.ts";
24
24
  import { createUsageStore } from "./server/store.ts";
25
+ import { ingestTurnAfter } from "./server/turn-ingest.ts";
25
26
  import {
26
27
  usageActivityByHourRpc,
27
28
  usageActivityByDayRpc,
@@ -29,6 +30,7 @@ import {
29
30
  usageAgentLifetimeRpc,
30
31
  usageAgentsRpc,
31
32
  usageAgentUnarchiveRpc,
33
+ usageByProjectRpc,
32
34
  usageByProviderRpc,
33
35
  usageExportRpc,
34
36
  usageHostInfoRpc,
@@ -45,73 +47,66 @@ import { explorerAgentDisplaySettings } from "./shared/explorer-agent-display.ts
45
47
  export default function contribute(server: PluginServerContext) {
46
48
  const store = createUsageStore();
47
49
  const background = createBackgroundSync(store);
50
+ const cache = createRpcCache({ generation: () => store.generation() });
48
51
  console.log(`[activity] store ready (driver=${store.driver})`);
49
52
  server.registerSettings(explorerAgentDisplaySettings);
50
53
 
51
- server.handle(usageSummaryRpc, (input, context) => {
52
- void background.request(context.paseo);
53
- return createSummaryHandler(store)(input);
54
- });
55
- server.handle(usageListRpc, (input, context) => {
56
- void background.request(context.paseo);
57
- return createListHandler(store)(input);
58
- });
59
- server.handle(usageSkillsByNameRpc, (input, context) => {
60
- void background.request(context.paseo);
61
- return createSkillsByNameHandler(store)(input, context);
62
- });
63
- server.handle(usageRecentSkillCallsRpc, (input, context) => {
64
- void background.request(context.paseo);
65
- return createRecentSkillCallsHandler(store)(input);
66
- });
67
- server.handle(usageRecentMcpCallsRpc, (input, context) => {
68
- void background.request(context.paseo);
69
- return createRecentMcpCallsHandler(store)(input);
70
- });
71
- server.handle(usageMcpByToolRpc, (input, context) => {
72
- void background.request(context.paseo);
73
- return createMcpByToolHandler(store)(input);
74
- });
75
- server.handle(usageByProviderRpc, (input, context) => {
76
- void background.request(context.paseo);
77
- return createByProviderHandler(store)(input);
78
- });
79
- server.handle(usageAgentsRpc, (input, context) => {
80
- void background.request(context.paseo);
81
- return createAgentsHandler(store)(input);
82
- });
54
+ /** Cached read RPC that also nudges the background history check. */
55
+ function read<I, O>(
56
+ rpc: { name: string },
57
+ handler: (input: I, context: PluginHandlerContext) => Promise<O>,
58
+ ) {
59
+ const cached = cache.wrap(rpc.name, handler);
60
+ return (input: I, context: PluginHandlerContext) => {
61
+ void background.request(context.paseo);
62
+ return cached(input, context);
63
+ };
64
+ }
65
+
66
+ server.handle(usageSummaryRpc, read(usageSummaryRpc, createSummaryHandler(store)));
67
+ server.handle(usageListRpc, read(usageListRpc, createListHandler(store)));
68
+ server.handle(usageSkillsByNameRpc, read(usageSkillsByNameRpc, createSkillsByNameHandler(store)));
69
+ server.handle(
70
+ usageRecentSkillCallsRpc,
71
+ read(usageRecentSkillCallsRpc, createRecentSkillCallsHandler(store)),
72
+ );
73
+ server.handle(
74
+ usageRecentMcpCallsRpc,
75
+ read(usageRecentMcpCallsRpc, createRecentMcpCallsHandler(store)),
76
+ );
77
+ server.handle(usageMcpByToolRpc, read(usageMcpByToolRpc, createMcpByToolHandler(store)));
78
+ server.handle(usageByProviderRpc, read(usageByProviderRpc, createByProviderHandler(store)));
79
+ server.handle(usageByProjectRpc, read(usageByProjectRpc, createByProjectHandler(store)));
80
+ server.handle(usageAgentsRpc, read(usageAgentsRpc, createAgentsHandler(store)));
83
81
  server.handle(usageAgentUnarchiveRpc, createUnarchiveAgentHandler(store));
84
- server.handle(usageActivityByDayRpc, (input, context) => {
85
- void background.request(context.paseo);
86
- return createActivityByDayHandler(store)(input);
87
- });
88
- server.handle(usageActivityByHourRpc, (input, context) => {
89
- void background.request(context.paseo);
90
- return createActivityByHourHandler(store)(input);
91
- });
92
- server.handle(usageAgentLifetimeRpc, (input, context) => {
93
- void background.request(context.paseo);
94
- return createAgentLifetimeHandler(store)(input);
95
- });
96
- server.handle(usageAgentCreationsRpc, (input, context) => {
97
- void background.request(context.paseo);
98
- return createAgentCreationsHandler(store)(input);
99
- });
82
+ server.handle(usageActivityByDayRpc, read(usageActivityByDayRpc, createActivityByDayHandler(store)));
83
+ server.handle(
84
+ usageActivityByHourRpc,
85
+ read(usageActivityByHourRpc, createActivityByHourHandler(store)),
86
+ );
87
+ server.handle(
88
+ usageAgentLifetimeRpc,
89
+ read(usageAgentLifetimeRpc, createAgentLifetimeHandler(store)),
90
+ );
91
+ server.handle(
92
+ usageAgentCreationsRpc,
93
+ read(usageAgentCreationsRpc, createAgentCreationsHandler(store)),
94
+ );
100
95
  server.handle(usageExportRpc, createExportHandler(store));
101
96
  server.handle(usageHostInfoRpc, () => ({ homeDir: homedir() }));
102
97
  server.handle(usageReadSkillRpc, createReadSkillHandler());
103
98
 
104
- const removeCreated = server.on("agent.created", (event, context) => {
99
+ const removeCreated = server.addHook("agent.create.after", async (event, context) => {
105
100
  void background.request(context.paseo);
106
101
  try {
107
102
  store.upsertAgents([agentRowFromHook(event.agent)]);
108
103
  console.log(`[activity] agent.created id=${event.agent.id}`);
109
104
  } catch (error) {
110
- console.error("[activity] failed to ingest agent.created", error);
105
+ console.error("[activity] failed to ingest agent.create.after", error);
111
106
  }
112
107
  });
113
108
 
114
- const removeArchived = server.on("agent.archived", (event, context) => {
109
+ const removeArchived = server.addHook("agent.archive.after", async (event, context) => {
115
110
  void background.request(context.paseo);
116
111
  try {
117
112
  store.upsertAgents([
@@ -122,37 +117,24 @@ export default function contribute(server: PluginServerContext) {
122
117
  ]);
123
118
  console.log(`[activity] agent.archived id=${event.agent.id}`);
124
119
  } catch (error) {
125
- console.error("[activity] failed to ingest agent.archived", error);
120
+ console.error("[activity] failed to ingest agent.archive.after", error);
126
121
  }
127
122
  });
128
123
 
129
- const removeTurnEnded = server.on("agent.turn_ended", (event, context) => {
124
+ const removeTurnEnded = server.addHook("agent.turn.after", async (event, context) => {
130
125
  void background.request(context.paseo);
131
126
  void (async () => {
132
127
  try {
133
- const existing = store.getAgent(event.agent.id);
134
- store.upsertAgents([
135
- agentRowFromHook(event.agent, {
136
- createdAt: existing?.createdAt,
137
- archivedAt: existing?.archivedAt,
138
- }),
139
- ]);
140
- const model = await resolveAgentModel(context.paseo, event.agent.id);
141
- store.upsertUserMessages(
142
- ingestUserMessages(event.timeline, event.agent, { model }),
143
- );
144
- // mcpServers resolved inside ingestTimeline (OpenCode config + paseo inject + agent persistence)
145
- const rows = ingestTimeline(event.timeline, event.agent, null, {
128
+ const rows = await ingestTurnAfter(store, context.paseo, event.agent, {
146
129
  homeDir: homedir(),
147
130
  });
148
- if (rows.length > 0) {
149
- store.upsertMany(rows);
131
+ if (rows > 0) {
150
132
  console.log(
151
- `[activity] turn_ended agent=${event.agent.id} rows=${rows.length} total=${store.count()}`,
133
+ `[activity] turn.after agent=${event.agent.id} rows=${rows} total=${store.count()}`,
152
134
  );
153
135
  }
154
136
  } catch (error) {
155
- console.error("[activity] failed to ingest agent.turn_ended", error);
137
+ console.error("[activity] failed to ingest agent.turn.after", error);
156
138
  }
157
139
  })();
158
140
  });