@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
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Pressable, ScrollView, Text, View } from "react-native";
|
|
3
|
+
import type { ActivityDay } from "../shared/usage.ts";
|
|
4
|
+
import { activityLevel, buildActivityCalendar, type HeatmapMode } from "../shared/activity.ts";
|
|
5
|
+
import { useAppLanguage } from "./use-app-language.ts";
|
|
6
|
+
export { computeStreaks, type HeatmapMode } from "../shared/activity.ts";
|
|
7
|
+
|
|
8
|
+
type ThemeColors = {
|
|
9
|
+
accent: string; border: string; foreground: string; foregroundMuted: string;
|
|
10
|
+
surface0: string; surface1: string; surface2: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Derive the activity palette from the active theme.
|
|
14
|
+
function mix(base: string, accent: string, amount: number): string {
|
|
15
|
+
const parse = (value: string) => {
|
|
16
|
+
const hex = value.replace("#", "");
|
|
17
|
+
const expanded = hex.length === 3 || hex.length === 4
|
|
18
|
+
? hex.split("").map((c) => c + c).join("")
|
|
19
|
+
: hex;
|
|
20
|
+
// Use first 6 digits only — ignore trailing alpha on 8-digit hex.
|
|
21
|
+
const rgb = expanded.slice(0, 6);
|
|
22
|
+
return [0, 2, 4].map((i) => parseInt(rgb.slice(i, i + 2), 16));
|
|
23
|
+
};
|
|
24
|
+
const a = parse(base); const b = parse(accent);
|
|
25
|
+
return `rgb(${a.map((v, i) => Math.round(v + (b[i]! - v) * amount)).join(",")})`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function plural(count: number, singular: string, pluralForm = `${singular}s`): string {
|
|
29
|
+
return `${count.toLocaleString()} ${count === 1 ? singular : pluralForm}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function ActivityHeatmap({ days, from, colors, compact, mode, onModeChange, modeOptions }: {
|
|
33
|
+
days: readonly ActivityDay[]; from?: string; colors: ThemeColors; compact?: boolean;
|
|
34
|
+
mode: HeatmapMode; onModeChange: (mode: HeatmapMode) => void;
|
|
35
|
+
modeOptions: ReadonlyArray<{ id: HeatmapMode; label: string }>;
|
|
36
|
+
}) {
|
|
37
|
+
const locale = useAppLanguage();
|
|
38
|
+
const [width, setWidth] = useState(0);
|
|
39
|
+
const [gridTop, setGridTop] = useState(0);
|
|
40
|
+
const [scrollX, setScrollX] = useState(0);
|
|
41
|
+
const [tooltipSize, setTooltipSize] = useState({ width: 220, height: 28 });
|
|
42
|
+
const [selected, setSelected] = useState<string | null>(null);
|
|
43
|
+
const [hovered, setHovered] = useState<string | null>(null);
|
|
44
|
+
useEffect(() => { setSelected(null); setHovered(null); }, [from, mode, days]);
|
|
45
|
+
const { weeks, months, max } = useMemo(() => buildActivityCalendar(days, mode, from, new Date(), locale), [days, mode, from, locale]);
|
|
46
|
+
const gap = compact ? 2 : 3;
|
|
47
|
+
// Fit the full year into the measured width (no min floor — avoid horizontal overflow).
|
|
48
|
+
const cellSize =
|
|
49
|
+
width > 0 && weeks.length > 0
|
|
50
|
+
? Math.min(18, Math.max(0, (width - gap * (weeks.length - 1)) / weeks.length))
|
|
51
|
+
: 0;
|
|
52
|
+
const gridWidth = weeks.length > 0 ? weeks.length * (cellSize + gap) - gap : 0;
|
|
53
|
+
const needsScroll = gridWidth > width + 0.5;
|
|
54
|
+
const palette = [colors.surface2, ...[0.22, 0.43, 0.68, 1].map(n => mix(colors.surface2, colors.accent, n))];
|
|
55
|
+
const activeKey = hovered ?? selected;
|
|
56
|
+
const activeIndex = weeks.flat().findIndex(cell => cell.key === activeKey);
|
|
57
|
+
const active = activeIndex >= 0 ? weeks.flat()[activeIndex] : undefined;
|
|
58
|
+
const anchorX = Math.floor(activeIndex / 7) * (cellSize + gap) + cellSize / 2 - scrollX;
|
|
59
|
+
const anchorY = gridTop + (activeIndex % 7) * (cellSize + gap);
|
|
60
|
+
const tooltipLeft = Math.max(0, Math.min(anchorX - tooltipSize.width / 2, width - tooltipSize.width));
|
|
61
|
+
const tooltipTop = Math.max(0, anchorY - tooltipSize.height - 8);
|
|
62
|
+
const dateLabel = active ? (() => {
|
|
63
|
+
const [year, month, day] = active.key.split("-").map(Number);
|
|
64
|
+
return new Date(year!, month! - 1, day!).toLocaleDateString(locale, {
|
|
65
|
+
month: "short", day: "numeric", year: year !== new Date().getFullYear() ? "numeric" : undefined,
|
|
66
|
+
});
|
|
67
|
+
})() : "";
|
|
68
|
+
const datePrefix = mode === "weekly" ? "in week containing" : mode === "cumulative" ? "through" : "on";
|
|
69
|
+
const tooltipText = active
|
|
70
|
+
? `${plural(active.skills, "skill")}, ${plural(active.mcp, "mcp")}, ${plural(active.agents, "agent")}, ${plural(active.messages, "message")} ${datePrefix} ${dateLabel}`
|
|
71
|
+
: "";
|
|
72
|
+
const muted = { color: colors.foregroundMuted, fontSize: 12 };
|
|
73
|
+
const axisWidth = needsScroll ? gridWidth : width;
|
|
74
|
+
const modeLabel = mode === "weekly" ? "Week containing" : mode === "cumulative" ? "Through" : "";
|
|
75
|
+
return (
|
|
76
|
+
<View style={{ gap: compact ? 16 : 22 }} onLayout={event => setWidth(event.nativeEvent.layout.width)}>
|
|
77
|
+
<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>
|
|
79
|
+
<View style={{ flexDirection: "row", gap: compact ? 14 : 20 }}>
|
|
80
|
+
{modeOptions.map(option => (
|
|
81
|
+
<Pressable key={option.id} accessibilityRole="tab" accessibilityState={{ selected: mode === option.id }} onPress={() => onModeChange(option.id)} style={{ paddingVertical: 6 }}>
|
|
82
|
+
<Text style={{ color: mode === option.id ? colors.foreground : colors.foregroundMuted, fontSize: compact ? 13 : 15 }}>{option.label}</Text>
|
|
83
|
+
</Pressable>
|
|
84
|
+
))}
|
|
85
|
+
</View>
|
|
86
|
+
</View>
|
|
87
|
+
<ScrollView
|
|
88
|
+
horizontal
|
|
89
|
+
scrollEnabled={needsScroll}
|
|
90
|
+
showsHorizontalScrollIndicator={needsScroll}
|
|
91
|
+
onLayout={event => setGridTop(event.nativeEvent.layout.y)}
|
|
92
|
+
onScroll={event => setScrollX(event.nativeEvent.contentOffset.x)}
|
|
93
|
+
scrollEventThrottle={16}
|
|
94
|
+
>
|
|
95
|
+
<View style={{ width: Math.max(0, axisWidth), paddingBottom: 4 }}>
|
|
96
|
+
<View style={{ flexDirection: "row", gap }}>
|
|
97
|
+
{weeks.map((week, i) => (
|
|
98
|
+
<View key={i} style={{ gap }}>
|
|
99
|
+
{week.map(cell => {
|
|
100
|
+
const hidden = cell.future || cell.excluded;
|
|
101
|
+
return (
|
|
102
|
+
<Pressable key={cell.key} disabled={hidden} accessibilityRole="button"
|
|
103
|
+
accessibilityLabel={`${modeLabel} ${cell.key}: ${cell.total} activity, ${cell.skills} skills, ${cell.mcp} MCP, ${cell.agents} agents, ${cell.messages} messages`}
|
|
104
|
+
accessibilityState={{ selected: activeKey === cell.key }}
|
|
105
|
+
onHoverIn={() => setHovered(cell.key)} onHoverOut={() => setHovered(null)}
|
|
106
|
+
onFocus={() => setHovered(cell.key)} onBlur={() => setHovered(null)}
|
|
107
|
+
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 }} />
|
|
110
|
+
);
|
|
111
|
+
})}
|
|
112
|
+
</View>
|
|
113
|
+
))}
|
|
114
|
+
</View>
|
|
115
|
+
<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
|
+
))}
|
|
121
|
+
</View>
|
|
122
|
+
</View>
|
|
123
|
+
</ScrollView>
|
|
124
|
+
{active && anchorX >= 0 && anchorX <= width ? (
|
|
125
|
+
<View pointerEvents="none"
|
|
126
|
+
onLayout={event => setTooltipSize({ width: event.nativeEvent.layout.width, height: event.nativeEvent.layout.height })}
|
|
127
|
+
style={{ position: "absolute", left: tooltipLeft, top: tooltipTop, zIndex: 10,
|
|
128
|
+
maxWidth: width || 220, paddingHorizontal: 10, paddingVertical: 6,
|
|
129
|
+
borderRadius: 8, backgroundColor: colors.surface2,
|
|
130
|
+
borderWidth: 1, borderColor: colors.border }}>
|
|
131
|
+
<Text accessibilityLiveRegion="polite" style={{ color: colors.foreground, fontSize: 12, lineHeight: 16 }}>
|
|
132
|
+
{tooltipText}
|
|
133
|
+
</Text>
|
|
134
|
+
</View>
|
|
135
|
+
) : null}
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
}
|