@koinzhang/paseo-plugin-activity 0.1.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.
- package/client/activity-heatmap.tsx +138 -0
- package/client/global-surface.tsx +689 -0
- package/client/panel.tsx +423 -0
- package/client/pending-skill.ts +50 -0
- package/client/pill-data-cache.test.ts +68 -0
- package/client/pill-data-cache.ts +37 -0
- package/client/pill.tsx +211 -0
- package/client/provider-filter.test.ts +95 -0
- package/client/provider-filter.ts +44 -0
- package/client/rank-color.test.ts +35 -0
- package/client/rank-color.ts +69 -0
- package/client/usage-popover.tsx +383 -0
- package/client/usage-query.tsx +54 -0
- package/client/usage-stats.tsx +18 -0
- package/client/use-app-language.ts +14 -0
- package/client/web.ts +28 -0
- package/index.client.tsx +62 -0
- package/index.server.ts +128 -0
- package/package.json +31 -0
- package/paseo-plugin.json +6 -0
- package/server/agents.test.ts +67 -0
- package/server/agents.ts +75 -0
- package/server/background-sync.test.ts +143 -0
- package/server/background-sync.ts +105 -0
- package/server/handlers-query.test.ts +91 -0
- package/server/handlers.ts +531 -0
- package/server/host-types.ts +14 -0
- package/server/ingest.test.ts +233 -0
- package/server/ingest.ts +277 -0
- package/server/mcp-servers.test.ts +70 -0
- package/server/mcp-servers.ts +212 -0
- package/server/messages.test.ts +150 -0
- package/server/migrate-data.test.ts +65 -0
- package/server/migrate-data.ts +54 -0
- package/server/resolve-model.test.ts +11 -0
- package/server/resolve-model.ts +30 -0
- package/server/skill-path.test.ts +56 -0
- package/server/skill-path.ts +85 -0
- package/server/store.test.ts +221 -0
- package/server/store.ts +909 -0
- package/server/ttl-cache.ts +34 -0
- package/shared/activity.test.ts +86 -0
- package/shared/activity.ts +185 -0
- package/shared/classify.test.ts +306 -0
- package/shared/classify.ts +378 -0
- package/shared/format.test.ts +48 -0
- package/shared/format.ts +45 -0
- package/shared/insights.test.ts +122 -0
- package/shared/insights.ts +188 -0
- package/shared/plugin-id.ts +7 -0
- package/shared/usage.test.ts +668 -0
- package/shared/usage.ts +726 -0
package/client/panel.tsx
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { type PluginAgentPanelProps, useAgent, useRpc } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
import {
|
|
6
|
+
ActivityIndicator,
|
|
7
|
+
Platform,
|
|
8
|
+
Pressable,
|
|
9
|
+
ScrollView,
|
|
10
|
+
Text,
|
|
11
|
+
View,
|
|
12
|
+
type TextStyle,
|
|
13
|
+
} from "react-native";
|
|
14
|
+
import {
|
|
15
|
+
usageMcpByToolRpc,
|
|
16
|
+
usageReadSkillRpc,
|
|
17
|
+
usageSkillsByNameRpc,
|
|
18
|
+
usageSummaryRpc,
|
|
19
|
+
} from "../shared/usage.ts";
|
|
20
|
+
import { formatDisplayName, formatLocalDateTime } from "../shared/format.ts";
|
|
21
|
+
import {
|
|
22
|
+
clearPendingSkillOpen,
|
|
23
|
+
consumePendingSkillOpen,
|
|
24
|
+
subscribePendingSkillOpen,
|
|
25
|
+
} from "./pending-skill.ts";
|
|
26
|
+
|
|
27
|
+
import { UsageStats } from "./usage-stats.tsx";
|
|
28
|
+
|
|
29
|
+
type TabId = "skills" | "mcp";
|
|
30
|
+
|
|
31
|
+
type SkillDetail = {
|
|
32
|
+
skillName: string;
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
|
|
37
|
+
|
|
38
|
+
function CountText({
|
|
39
|
+
value,
|
|
40
|
+
styles,
|
|
41
|
+
}: {
|
|
42
|
+
value: number | string;
|
|
43
|
+
styles: { countText: TextStyle };
|
|
44
|
+
}): ReactNode {
|
|
45
|
+
return <Text style={styles.countText}>{value}</Text>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function UsagePanel({ theme, layout, agentId, navigation }: PluginAgentPanelProps) {
|
|
49
|
+
const [tab, setTab] = useState<TabId | null>(null);
|
|
50
|
+
const [skillDetail, setSkillDetail] = useState<SkillDetail | null>(null);
|
|
51
|
+
const padding = layout.compact ? 16 : 28;
|
|
52
|
+
const agentTitle = useAgent(agentId, (agent) => agent.title);
|
|
53
|
+
const openAgent = navigation?.openAgent;
|
|
54
|
+
const conversationLabel = agentTitle ?? agentId;
|
|
55
|
+
|
|
56
|
+
const skillsByNameRpc = useRpc(usageSkillsByNameRpc);
|
|
57
|
+
const mcpByToolRpc = useRpc(usageMcpByToolRpc);
|
|
58
|
+
const summaryRpc = useRpc(usageSummaryRpc);
|
|
59
|
+
const readSkillRpc = useRpc(usageReadSkillRpc);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
function applyPending() {
|
|
63
|
+
const pending = consumePendingSkillOpen(agentId);
|
|
64
|
+
if (!pending) return;
|
|
65
|
+
setSkillDetail({ skillName: pending.skillName, path: pending.path });
|
|
66
|
+
setTab("skills");
|
|
67
|
+
// Delay clear so openPanel / Strict Mode remount can still read the same pending.
|
|
68
|
+
setTimeout(() => clearPendingSkillOpen(agentId, pending), 1_000);
|
|
69
|
+
}
|
|
70
|
+
applyPending();
|
|
71
|
+
return subscribePendingSkillOpen(applyPending);
|
|
72
|
+
}, [agentId]);
|
|
73
|
+
|
|
74
|
+
const skillsByName = useQuery({
|
|
75
|
+
refetchInterval: 15_000,
|
|
76
|
+
queryKey: ["activity", "skills-by-name", agentId],
|
|
77
|
+
queryFn: () => skillsByNameRpc({ agentId }),
|
|
78
|
+
retry: false,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const mcpByTool = useQuery({
|
|
82
|
+
refetchInterval: 15_000,
|
|
83
|
+
queryKey: ["activity", "mcp-by-tool", agentId],
|
|
84
|
+
queryFn: () => mcpByToolRpc({ agentId }),
|
|
85
|
+
retry: false,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const usageSummary = useQuery({
|
|
89
|
+
refetchInterval: 15_000,
|
|
90
|
+
queryKey: ["activity", "summary", agentId],
|
|
91
|
+
queryFn: () => summaryRpc({ agentId }),
|
|
92
|
+
retry: false,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const skillFile = useQuery({
|
|
96
|
+
queryKey: ["activity", "read-skill", skillDetail?.path ?? ""],
|
|
97
|
+
queryFn: () => readSkillRpc({ path: skillDetail!.path }),
|
|
98
|
+
enabled: Boolean(skillDetail?.path),
|
|
99
|
+
retry: false,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const skillItems = useMemo(() => {
|
|
103
|
+
return (skillsByName.data?.items ?? [])
|
|
104
|
+
.filter((item) => item.total > 0)
|
|
105
|
+
.slice()
|
|
106
|
+
.sort((a, b) => {
|
|
107
|
+
const ta = a.lastUsedAt ?? "";
|
|
108
|
+
const tb = b.lastUsedAt ?? "";
|
|
109
|
+
return tb.localeCompare(ta) || a.skillName.localeCompare(b.skillName);
|
|
110
|
+
});
|
|
111
|
+
}, [skillsByName.data]);
|
|
112
|
+
|
|
113
|
+
const mcpItems = useMemo(() => {
|
|
114
|
+
return (mcpByTool.data?.items ?? []).slice().sort((a, b) => {
|
|
115
|
+
const ta = a.lastUsedAt ?? "";
|
|
116
|
+
const tb = b.lastUsedAt ?? "";
|
|
117
|
+
return (
|
|
118
|
+
tb.localeCompare(ta) ||
|
|
119
|
+
a.server.localeCompare(b.server) ||
|
|
120
|
+
a.tool.localeCompare(b.tool)
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
}, [mcpByTool.data]);
|
|
124
|
+
|
|
125
|
+
const tabs = useMemo(() => {
|
|
126
|
+
const next: Array<{ id: TabId; label: string }> = [];
|
|
127
|
+
if (skillItems.length > 0) next.push({ id: "skills", label: "Skills" });
|
|
128
|
+
if (mcpItems.length > 0) next.push({ id: "mcp", label: "MCP" });
|
|
129
|
+
return next;
|
|
130
|
+
}, [skillItems.length, mcpItems.length]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (tabs.length === 0) {
|
|
134
|
+
setTab(null);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!tab || !tabs.some((item) => item.id === tab)) {
|
|
138
|
+
setTab(tabs[0]!.id);
|
|
139
|
+
}
|
|
140
|
+
}, [tabs, tab]);
|
|
141
|
+
|
|
142
|
+
const styles = useMemo(
|
|
143
|
+
() => ({
|
|
144
|
+
screen: { flex: 1, backgroundColor: theme.colors.surface0 },
|
|
145
|
+
content: {
|
|
146
|
+
padding,
|
|
147
|
+
paddingBottom: padding + 24,
|
|
148
|
+
gap: layout.compact ? 20 : 28,
|
|
149
|
+
maxWidth: 1000,
|
|
150
|
+
width: "100%" as const,
|
|
151
|
+
alignSelf: "center" as const,
|
|
152
|
+
},
|
|
153
|
+
sectionTitle: {
|
|
154
|
+
color: theme.colors.foreground,
|
|
155
|
+
fontSize: layout.compact ? 18 : 20,
|
|
156
|
+
fontWeight: "600" as const,
|
|
157
|
+
flexShrink: 1,
|
|
158
|
+
letterSpacing: -0.3,
|
|
159
|
+
},
|
|
160
|
+
rangeBar: {
|
|
161
|
+
flexDirection: "row" as const,
|
|
162
|
+
alignItems: "center" as const,
|
|
163
|
+
alignSelf: "flex-start" as const,
|
|
164
|
+
gap: 20,
|
|
165
|
+
},
|
|
166
|
+
rangeSegment: {
|
|
167
|
+
paddingVertical: 8,
|
|
168
|
+
},
|
|
169
|
+
rangeSegmentActive: {
|
|
170
|
+
borderBottomWidth: 1,
|
|
171
|
+
borderBottomColor: theme.colors.foreground,
|
|
172
|
+
},
|
|
173
|
+
chipText: {
|
|
174
|
+
color: theme.colors.foregroundMuted,
|
|
175
|
+
fontSize: 13,
|
|
176
|
+
fontWeight: "500" as const,
|
|
177
|
+
},
|
|
178
|
+
chipTextActive: {
|
|
179
|
+
color: theme.colors.foreground,
|
|
180
|
+
fontSize: 13,
|
|
181
|
+
fontWeight: "600" as const,
|
|
182
|
+
},
|
|
183
|
+
panel: {
|
|
184
|
+
gap: 4,
|
|
185
|
+
overflow: "hidden" as const,
|
|
186
|
+
},
|
|
187
|
+
listRow: {
|
|
188
|
+
flexDirection: "row" as const,
|
|
189
|
+
alignItems: "center" as const,
|
|
190
|
+
gap: 12,
|
|
191
|
+
paddingHorizontal: 0,
|
|
192
|
+
paddingVertical: 12,
|
|
193
|
+
borderTopWidth: 0,
|
|
194
|
+
borderTopColor: theme.colors.border,
|
|
195
|
+
},
|
|
196
|
+
listRowFirst: {
|
|
197
|
+
borderTopWidth: 0,
|
|
198
|
+
},
|
|
199
|
+
listMain: {
|
|
200
|
+
flex: 1,
|
|
201
|
+
minWidth: 0,
|
|
202
|
+
gap: 3,
|
|
203
|
+
},
|
|
204
|
+
listTitle: {
|
|
205
|
+
color: theme.colors.foreground,
|
|
206
|
+
fontSize: 14,
|
|
207
|
+
fontWeight: "500" as const,
|
|
208
|
+
},
|
|
209
|
+
listLink: {
|
|
210
|
+
color: theme.colors.foreground,
|
|
211
|
+
fontSize: 14,
|
|
212
|
+
fontWeight: "500" as const,
|
|
213
|
+
},
|
|
214
|
+
listMeta: {
|
|
215
|
+
color: theme.colors.foregroundMuted,
|
|
216
|
+
fontSize: 12,
|
|
217
|
+
},
|
|
218
|
+
conversationLink: {
|
|
219
|
+
color: theme.colors.accent,
|
|
220
|
+
fontSize: 12,
|
|
221
|
+
},
|
|
222
|
+
countText: {
|
|
223
|
+
color: theme.colors.foregroundMuted,
|
|
224
|
+
fontSize: 13,
|
|
225
|
+
fontVariant: ["tabular-nums" as const],
|
|
226
|
+
minWidth: 24,
|
|
227
|
+
textAlign: "right" as const,
|
|
228
|
+
},
|
|
229
|
+
empty: {
|
|
230
|
+
color: theme.colors.foregroundMuted,
|
|
231
|
+
fontSize: 13,
|
|
232
|
+
},
|
|
233
|
+
backRow: {
|
|
234
|
+
flexDirection: "row" as const,
|
|
235
|
+
alignItems: "center" as const,
|
|
236
|
+
gap: 4,
|
|
237
|
+
alignSelf: "flex-start" as const,
|
|
238
|
+
},
|
|
239
|
+
back: {
|
|
240
|
+
color: theme.colors.foregroundMuted,
|
|
241
|
+
fontSize: 13,
|
|
242
|
+
fontWeight: "500" as const,
|
|
243
|
+
},
|
|
244
|
+
body: {
|
|
245
|
+
color: theme.colors.foreground,
|
|
246
|
+
fontSize: 13,
|
|
247
|
+
fontFamily: MONO,
|
|
248
|
+
lineHeight: 22,
|
|
249
|
+
backgroundColor: theme.colors.surface1,
|
|
250
|
+
padding: 16,
|
|
251
|
+
borderRadius: 12,
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
[theme, layout.compact, padding],
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const loading = skillsByName.isLoading || mcpByTool.isLoading;
|
|
258
|
+
const error = skillsByName.error ?? mcpByTool.error;
|
|
259
|
+
|
|
260
|
+
if (skillDetail) {
|
|
261
|
+
return (
|
|
262
|
+
<ScrollView style={styles.screen} contentContainerStyle={styles.content}>
|
|
263
|
+
<Pressable
|
|
264
|
+
accessibilityRole="button"
|
|
265
|
+
onPress={() => {
|
|
266
|
+
clearPendingSkillOpen(agentId);
|
|
267
|
+
setSkillDetail(null);
|
|
268
|
+
}}
|
|
269
|
+
style={styles.backRow}
|
|
270
|
+
>
|
|
271
|
+
<Icon name="ChevronLeft" size={16} color={theme.colors.foregroundMuted} />
|
|
272
|
+
<Text style={styles.back}>Skills</Text>
|
|
273
|
+
</Pressable>
|
|
274
|
+
<Text style={styles.sectionTitle}>{formatDisplayName(skillDetail.skillName)}</Text>
|
|
275
|
+
{skillFile.isLoading ? <ActivityIndicator color={theme.colors.accent} /> : null}
|
|
276
|
+
{skillFile.error ? (
|
|
277
|
+
<Text style={{ color: theme.colors.statusDanger }}>
|
|
278
|
+
{skillFile.error instanceof Error ? skillFile.error.message : String(skillFile.error)}
|
|
279
|
+
</Text>
|
|
280
|
+
) : null}
|
|
281
|
+
{skillFile.data ? (
|
|
282
|
+
<Text style={styles.body} selectable>
|
|
283
|
+
{skillFile.data.body}
|
|
284
|
+
</Text>
|
|
285
|
+
) : null}
|
|
286
|
+
</ScrollView>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const compact = layout.compact;
|
|
291
|
+
|
|
292
|
+
return (
|
|
293
|
+
<ScrollView style={styles.screen} contentContainerStyle={styles.content}>
|
|
294
|
+
<View style={{ gap: 6 }}>
|
|
295
|
+
{!compact ? <Text style={styles.sectionTitle}>Activity</Text> : null}
|
|
296
|
+
{openAgent ? (
|
|
297
|
+
<Text
|
|
298
|
+
accessibilityRole="link"
|
|
299
|
+
accessibilityLabel={`Open conversation ${conversationLabel}`}
|
|
300
|
+
style={styles.conversationLink}
|
|
301
|
+
onPress={() => openAgent({ agentId })}
|
|
302
|
+
>
|
|
303
|
+
{conversationLabel}
|
|
304
|
+
</Text>
|
|
305
|
+
) : (
|
|
306
|
+
<Text style={styles.listMeta}>{conversationLabel}</Text>
|
|
307
|
+
)}
|
|
308
|
+
</View>
|
|
309
|
+
{!loading && !error ? <UsageStats compact={layout.compact} colors={theme.colors} items={[
|
|
310
|
+
{ label: "Skill calls", value: skillItems.reduce((sum, item) => sum + item.total, 0).toLocaleString() },
|
|
311
|
+
{ label: "MCP calls", value: mcpItems.reduce((sum, item) => sum + item.count, 0).toLocaleString() },
|
|
312
|
+
{ label: "Shell calls", value: (usageSummary.data?.shellCalls ?? 0).toLocaleString() },
|
|
313
|
+
{ label: "File reads", value: (usageSummary.data?.fileReads ?? 0).toLocaleString() },
|
|
314
|
+
{ label: "File writes", value: (usageSummary.data?.fileWrites ?? 0).toLocaleString() },
|
|
315
|
+
{ label: "Tools explored", value: String(skillItems.length + mcpItems.length) },
|
|
316
|
+
]} /> : null}
|
|
317
|
+
{tabs.length > 1 ? (
|
|
318
|
+
<View style={styles.rangeBar}>
|
|
319
|
+
{tabs.map((item) => {
|
|
320
|
+
const active = tab === item.id;
|
|
321
|
+
return (
|
|
322
|
+
<Pressable
|
|
323
|
+
key={item.id}
|
|
324
|
+
accessibilityRole="tab"
|
|
325
|
+
accessibilityState={{ selected: active }}
|
|
326
|
+
onPress={() => setTab(item.id)}
|
|
327
|
+
style={[styles.rangeSegment, active ? styles.rangeSegmentActive : null]}
|
|
328
|
+
>
|
|
329
|
+
<Text style={active ? styles.chipTextActive : styles.chipText}>{item.label}</Text>
|
|
330
|
+
</Pressable>
|
|
331
|
+
);
|
|
332
|
+
})}
|
|
333
|
+
</View>
|
|
334
|
+
) : null}
|
|
335
|
+
|
|
336
|
+
{loading ? <ActivityIndicator color={theme.colors.accent} /> : null}
|
|
337
|
+
{error ? (
|
|
338
|
+
<Text style={{ color: theme.colors.statusDanger }}>
|
|
339
|
+
{error instanceof Error ? error.message : String(error)}
|
|
340
|
+
</Text>
|
|
341
|
+
) : null}
|
|
342
|
+
|
|
343
|
+
{!loading && !error && tabs.length === 0 ? (
|
|
344
|
+
<View style={{ gap: 12 }}>
|
|
345
|
+
{!compact ? <Text style={styles.sectionTitle}>Activity</Text> : null}
|
|
346
|
+
<Text style={styles.empty}>No skill or MCP calls yet</Text>
|
|
347
|
+
</View>
|
|
348
|
+
) : null}
|
|
349
|
+
|
|
350
|
+
{tab === "skills" ? (
|
|
351
|
+
<View style={{ gap: 12 }}>
|
|
352
|
+
<Text style={styles.sectionTitle}>Skills</Text>
|
|
353
|
+
<View style={styles.panel}>
|
|
354
|
+
{skillItems.map((item, index) => {
|
|
355
|
+
const name = formatDisplayName(item.skillName);
|
|
356
|
+
const title = item.skillPath ? (
|
|
357
|
+
<Pressable
|
|
358
|
+
accessibilityRole="link"
|
|
359
|
+
accessibilityLabel={`Open ${name} SKILL.md`}
|
|
360
|
+
onPress={() =>
|
|
361
|
+
setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
|
|
362
|
+
}
|
|
363
|
+
>
|
|
364
|
+
<Text style={styles.listLink} numberOfLines={1}>
|
|
365
|
+
{name}
|
|
366
|
+
</Text>
|
|
367
|
+
</Pressable>
|
|
368
|
+
) : (
|
|
369
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
370
|
+
{name}
|
|
371
|
+
</Text>
|
|
372
|
+
);
|
|
373
|
+
return (
|
|
374
|
+
<View
|
|
375
|
+
key={item.skillName}
|
|
376
|
+
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
377
|
+
>
|
|
378
|
+
<Icon name="Sparkles" size={18} color={theme.colors.foregroundMuted} />
|
|
379
|
+
<View style={styles.listMain}>
|
|
380
|
+
{title}
|
|
381
|
+
<Text style={styles.listMeta}>
|
|
382
|
+
Last {formatLocalDateTime(item.lastUsedAt)}
|
|
383
|
+
</Text>
|
|
384
|
+
</View>
|
|
385
|
+
<CountText value={item.total} styles={styles} />
|
|
386
|
+
</View>
|
|
387
|
+
);
|
|
388
|
+
})}
|
|
389
|
+
</View>
|
|
390
|
+
</View>
|
|
391
|
+
) : null}
|
|
392
|
+
|
|
393
|
+
{tab === "mcp" ? (
|
|
394
|
+
<View style={{ gap: 12 }}>
|
|
395
|
+
<Text style={styles.sectionTitle}>MCP</Text>
|
|
396
|
+
<View style={styles.panel}>
|
|
397
|
+
{mcpItems.map((item, index) => (
|
|
398
|
+
<View
|
|
399
|
+
key={`${item.server}.${item.tool}`}
|
|
400
|
+
style={[styles.listRow, index === 0 ? styles.listRowFirst : null]}
|
|
401
|
+
>
|
|
402
|
+
<Icon name="Plug" size={18} color={theme.colors.foregroundMuted} />
|
|
403
|
+
<View style={styles.listMain}>
|
|
404
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
405
|
+
{formatDisplayName(`${item.server}.${item.tool}`)}
|
|
406
|
+
</Text>
|
|
407
|
+
<Text style={styles.listMeta}>
|
|
408
|
+
{item.failures > 0
|
|
409
|
+
? `${item.failures} failed`
|
|
410
|
+
: item.lastUsedAt
|
|
411
|
+
? `Last ${formatLocalDateTime(item.lastUsedAt)}`
|
|
412
|
+
: "—"}
|
|
413
|
+
</Text>
|
|
414
|
+
</View>
|
|
415
|
+
<CountText value={item.count} styles={styles} />
|
|
416
|
+
</View>
|
|
417
|
+
))}
|
|
418
|
+
</View>
|
|
419
|
+
</View>
|
|
420
|
+
) : null}
|
|
421
|
+
</ScrollView>
|
|
422
|
+
);
|
|
423
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Hand-off from pill popover → agent Activity panel for a SKILL.md detail view. */
|
|
2
|
+
|
|
3
|
+
export type PendingSkillOpen = {
|
|
4
|
+
agentId: string;
|
|
5
|
+
skillName: string;
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const pendingByAgent = new Map<string, PendingSkillOpen>();
|
|
10
|
+
const listeners = new Set<() => void>();
|
|
11
|
+
|
|
12
|
+
/** Keep pending readable across openPanel / Strict Mode remounts in the same turn. */
|
|
13
|
+
const PENDING_TTL_MS = 5_000;
|
|
14
|
+
|
|
15
|
+
function notify(): void {
|
|
16
|
+
for (const listener of listeners) listener();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function requestOpenSkillInPanel(next: PendingSkillOpen): void {
|
|
20
|
+
pendingByAgent.set(next.agentId, next);
|
|
21
|
+
notify();
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
if (pendingByAgent.get(next.agentId) === next) {
|
|
24
|
+
pendingByAgent.delete(next.agentId);
|
|
25
|
+
}
|
|
26
|
+
}, PENDING_TTL_MS);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Peek the pending open for this agent without clearing.
|
|
31
|
+
* Panel must call {@link clearPendingSkillOpen} after applying (delayed) or when
|
|
32
|
+
* the user leaves the detail view — immediate consume races with remount.
|
|
33
|
+
*/
|
|
34
|
+
export function consumePendingSkillOpen(agentId: string): PendingSkillOpen | null {
|
|
35
|
+
return pendingByAgent.get(agentId) ?? null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function clearPendingSkillOpen(agentId: string, expected?: PendingSkillOpen): void {
|
|
39
|
+
const current = pendingByAgent.get(agentId);
|
|
40
|
+
if (!current) return;
|
|
41
|
+
if (expected && current !== expected) return;
|
|
42
|
+
pendingByAgent.delete(agentId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function subscribePendingSkillOpen(listener: () => void): () => void {
|
|
46
|
+
listeners.add(listener);
|
|
47
|
+
return () => {
|
|
48
|
+
listeners.delete(listener);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { QueryClient, QueryObserver } from "@tanstack/react-query";
|
|
4
|
+
import {
|
|
5
|
+
__setPillDataCacheForTests,
|
|
6
|
+
seedPillDataForQuery,
|
|
7
|
+
type UsagePillData,
|
|
8
|
+
} from "./pill-data-cache.ts";
|
|
9
|
+
|
|
10
|
+
const sample: UsagePillData = {
|
|
11
|
+
skills: [{
|
|
12
|
+
skillName: "demo",
|
|
13
|
+
exact: 1,
|
|
14
|
+
inferred: 0,
|
|
15
|
+
low: 0,
|
|
16
|
+
total: 1,
|
|
17
|
+
lastUsedAt: "2026-09-19T12:00:00.000Z",
|
|
18
|
+
skillPath: null,
|
|
19
|
+
}],
|
|
20
|
+
mcpTools: [],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const empty: UsagePillData = {
|
|
24
|
+
skills: [],
|
|
25
|
+
mcpTools: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test("pill query key reuses cached data without a cold loading state", async () => {
|
|
29
|
+
const client = new QueryClient({
|
|
30
|
+
defaultOptions: { queries: { retry: false } },
|
|
31
|
+
});
|
|
32
|
+
const key = ["activity", "pill", "agent", "a1"];
|
|
33
|
+
client.setQueryData(key, sample);
|
|
34
|
+
let fetches = 0;
|
|
35
|
+
const observer = new QueryObserver(client, {
|
|
36
|
+
queryKey: key,
|
|
37
|
+
queryFn: async () => {
|
|
38
|
+
fetches += 1;
|
|
39
|
+
return sample;
|
|
40
|
+
},
|
|
41
|
+
staleTime: 0,
|
|
42
|
+
refetchOnMount: "always",
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
const result = observer.getCurrentResult();
|
|
46
|
+
assert.deepEqual(result.data, sample);
|
|
47
|
+
assert.equal(result.isLoading, false);
|
|
48
|
+
assert.equal(fetches, 0);
|
|
49
|
+
} finally {
|
|
50
|
+
observer.destroy();
|
|
51
|
+
client.clear();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("module pill cache seeds non-empty data and skips empty seeds", () => {
|
|
56
|
+
__setPillDataCacheForTests("a1", sample);
|
|
57
|
+
try {
|
|
58
|
+
assert.deepEqual(seedPillDataForQuery("a1"), sample);
|
|
59
|
+
} finally {
|
|
60
|
+
__setPillDataCacheForTests("a1", undefined);
|
|
61
|
+
}
|
|
62
|
+
__setPillDataCacheForTests("a1", empty);
|
|
63
|
+
try {
|
|
64
|
+
assert.equal(seedPillDataForQuery("a1"), undefined);
|
|
65
|
+
} finally {
|
|
66
|
+
__setPillDataCacheForTests("a1", undefined);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { formatUsagePillLabel } from "../shared/usage.ts";
|
|
2
|
+
import type { McpByToolItem, SkillByNameItem } from "../shared/usage.ts";
|
|
3
|
+
|
|
4
|
+
export type UsagePillData = {
|
|
5
|
+
skills: SkillByNameItem[];
|
|
6
|
+
mcpTools: McpByToolItem[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Survives separate React trees when icon and popover do not share a QueryClient. */
|
|
10
|
+
const pillDataCache = new Map<string, UsagePillData>();
|
|
11
|
+
|
|
12
|
+
export function pillDataIsEmpty(data: UsagePillData): boolean {
|
|
13
|
+
return formatUsagePillLabel(undefined, data.skills, data.mcpTools).length === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function seedPillDataForQuery(agentId: string): UsagePillData | undefined {
|
|
17
|
+
const cached = pillDataCache.get(agentId);
|
|
18
|
+
if (!cached || pillDataIsEmpty(cached)) return undefined;
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function writePillDataCache(agentId: string, data: UsagePillData): void {
|
|
23
|
+
pillDataCache.set(agentId, data);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function clearPillDataCache(agentId: string): void {
|
|
27
|
+
pillDataCache.delete(agentId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Test helper: seed / clear the cross-tree pill cache. */
|
|
31
|
+
export function __setPillDataCacheForTests(
|
|
32
|
+
agentId: string,
|
|
33
|
+
data: UsagePillData | undefined,
|
|
34
|
+
): void {
|
|
35
|
+
if (data === undefined) pillDataCache.delete(agentId);
|
|
36
|
+
else pillDataCache.set(agentId, data);
|
|
37
|
+
}
|