@koinzhang/paseo-plugin-activity 0.6.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.
- package/CHANGELOG.md +35 -1
- package/README.md +14 -7
- package/client/activity-heatmap.tsx +115 -74
- package/client/agent-creations.tsx +97 -88
- package/client/attention-pill.tsx +16 -5
- package/client/attention-popover.tsx +19 -23
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +168 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +236 -268
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +136 -103
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +83 -108
- package/client/provider-dropdown.tsx +131 -0
- package/client/provider-filter.test.ts +17 -13
- package/client/provider-filter.ts +5 -7
- package/client/rank-color.ts +3 -3
- package/client/ranking-bars.tsx +291 -0
- package/client/ui.tsx +339 -0
- package/client/usage-popover.tsx +62 -134
- package/client/usage-stats.tsx +29 -11
- package/client/use-agent-turn-end.ts +2 -1
- package/client/use-app-language.ts +17 -0
- package/client/web.ts +73 -18
- package/client/workspace/agent-row.tsx +18 -25
- package/client/workspace/agents-section.tsx +23 -20
- package/client/workspace/constants.ts +6 -6
- package/client/workspace/display-menu.tsx +5 -4
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +89 -103
- package/client/workspace/rank-section.tsx +36 -62
- package/client/workspace/terminals-section.tsx +13 -9
- package/index.client.tsx +40 -20
- package/index.server.ts +53 -51
- package/package.json +2 -2
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.ts +34 -4
- package/server/handlers-query.test.ts +27 -1
- package/server/handlers.ts +75 -31
- package/server/ingest.test.ts +8 -0
- package/server/messages.test.ts +96 -1
- package/server/prompt-dedupe.ts +52 -0
- package/server/rpc-cache.test.ts +74 -0
- package/server/rpc-cache.ts +48 -0
- package/server/store.test.ts +122 -0
- package/server/store.ts +313 -19
- package/server/ttl-cache.ts +3 -0
- package/shared/activity.test.ts +36 -0
- package/shared/activity.ts +37 -0
- package/shared/classify.test.ts +1 -10
- package/shared/classify.ts +3 -10
- package/shared/format.ts +10 -7
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +120 -81
- package/shared/insights.ts +124 -63
- package/shared/usage.test.ts +121 -0
- package/shared/usage.ts +191 -2
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { PluginButtonRegistration, PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { messagesFor } from "../shared/i18n.ts";
|
|
3
|
+
import { isPanelMounted, watchPanelPresence } from "./panel-visibility.ts";
|
|
4
|
+
import { currentAppLanguage, watchAppLanguage } from "./use-app-language.ts";
|
|
5
|
+
|
|
6
|
+
type WorkspacesApi = PluginClientContext["paseo"]["workspaces"];
|
|
7
|
+
type ListResult = Awaited<ReturnType<WorkspacesApi["list"]>>;
|
|
8
|
+
|
|
9
|
+
const BUTTON_ID = "workspace-activity";
|
|
10
|
+
const PANEL_ID = "workspace-activity";
|
|
11
|
+
const PAGE_LIMIT = 200;
|
|
12
|
+
|
|
13
|
+
const buttonTitle = () => messagesFor(currentAppLanguage()).commands.workspaceActivity;
|
|
14
|
+
|
|
15
|
+
/** One header button per workspace, following an entry-owned workspace directory subscription. */
|
|
16
|
+
export function contributeHeaderButtons(
|
|
17
|
+
client: PluginClientContext,
|
|
18
|
+
intervalMs = 15_000,
|
|
19
|
+
): () => void {
|
|
20
|
+
const workspaces = client.paseo.workspaces;
|
|
21
|
+
const buttons = new Map<string, PluginButtonRegistration>();
|
|
22
|
+
const report = (error: unknown) => console.error("[activity] workspace directory failed", error);
|
|
23
|
+
let disposed = false;
|
|
24
|
+
let connecting = false;
|
|
25
|
+
let generation = 0;
|
|
26
|
+
let release: (() => Promise<void>) | undefined;
|
|
27
|
+
|
|
28
|
+
function add(workspaceId: string) {
|
|
29
|
+
if (disposed || buttons.has(workspaceId)) return;
|
|
30
|
+
buttons.set(workspaceId, client.addHeaderButton({
|
|
31
|
+
id: BUTTON_ID,
|
|
32
|
+
workspaceId,
|
|
33
|
+
button: {
|
|
34
|
+
title: buttonTitle(),
|
|
35
|
+
icon: "Activity",
|
|
36
|
+
visible: !isPanelMounted(workspaceId),
|
|
37
|
+
behavior: {
|
|
38
|
+
kind: "action",
|
|
39
|
+
onPress() {
|
|
40
|
+
client.openPanel(PANEL_ID, { workspaceId, location: "explorer" });
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function remove(workspaceId: string) {
|
|
48
|
+
buttons.get(workspaceId)?.remove();
|
|
49
|
+
buttons.delete(workspaceId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function read(first?: ListResult) {
|
|
53
|
+
const run = ++generation;
|
|
54
|
+
try {
|
|
55
|
+
const ids = new Set<string>();
|
|
56
|
+
let page = first ?? await workspaces.list({ page: { limit: PAGE_LIMIT } });
|
|
57
|
+
for (let pages = 0; ; pages++) {
|
|
58
|
+
if (disposed || run !== generation) return;
|
|
59
|
+
for (const workspace of page.entries) ids.add(workspace.id);
|
|
60
|
+
if (!page.pageInfo.hasMore) break;
|
|
61
|
+
if (!page.pageInfo.nextCursor || pages >= 99) throw new Error("Incomplete workspace pagination");
|
|
62
|
+
page = await workspaces.list({ page: { limit: PAGE_LIMIT, cursor: page.pageInfo.nextCursor } });
|
|
63
|
+
}
|
|
64
|
+
for (const id of [...buttons.keys()]) if (!ids.has(id)) remove(id);
|
|
65
|
+
for (const id of ids) add(id);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (!disposed && run === generation) report(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function connect() {
|
|
72
|
+
if (disposed || connecting || release) return;
|
|
73
|
+
connecting = true;
|
|
74
|
+
try {
|
|
75
|
+
const result = await workspaces.list({ page: { limit: PAGE_LIMIT }, subscribe: {} });
|
|
76
|
+
if (disposed) {
|
|
77
|
+
await result.subscription.release();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
release = () => result.subscription.release();
|
|
81
|
+
result.subscription.subscribe({
|
|
82
|
+
// Called immediately and again after reconnect.
|
|
83
|
+
snapshot: (page) => { void read(page); },
|
|
84
|
+
update: (message) => {
|
|
85
|
+
if (disposed || message.type !== "workspace_update") return;
|
|
86
|
+
const update = message.payload;
|
|
87
|
+
if (update.kind === "upsert") add(update.workspace.id);
|
|
88
|
+
else remove(update.id);
|
|
89
|
+
},
|
|
90
|
+
error: (error) => {
|
|
91
|
+
if (disposed) return;
|
|
92
|
+
report(error);
|
|
93
|
+
const stop = release;
|
|
94
|
+
release = undefined;
|
|
95
|
+
if (stop) void stop().catch(report);
|
|
96
|
+
void read();
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!disposed) {
|
|
101
|
+
report(error);
|
|
102
|
+
await read();
|
|
103
|
+
}
|
|
104
|
+
} finally {
|
|
105
|
+
connecting = false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const timer = setInterval(() => {
|
|
110
|
+
if (!release) void connect();
|
|
111
|
+
else void read();
|
|
112
|
+
}, intervalMs);
|
|
113
|
+
void connect();
|
|
114
|
+
|
|
115
|
+
const stopLanguage = watchAppLanguage(() => {
|
|
116
|
+
const title = buttonTitle();
|
|
117
|
+
for (const button of buttons.values()) button.update({ title });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const stopPresence = watchPanelPresence((workspaceId) => {
|
|
121
|
+
buttons.get(workspaceId)?.update({ visible: !isPanelMounted(workspaceId) });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return () => {
|
|
125
|
+
disposed = true;
|
|
126
|
+
++generation;
|
|
127
|
+
clearInterval(timer);
|
|
128
|
+
stopLanguage();
|
|
129
|
+
stopPresence();
|
|
130
|
+
const stop = release;
|
|
131
|
+
release = undefined;
|
|
132
|
+
if (stop) void stop().catch(report);
|
|
133
|
+
buttons.forEach((button) => button.remove());
|
|
134
|
+
buttons.clear();
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { PanResponder, Pressable, ScrollView, Text, View } from "react-native";
|
|
2
|
+
import { Animated, Easing, PanResponder, Pressable, ScrollView, Text, View } from "react-native";
|
|
3
3
|
import type { ActivityHour } from "../shared/usage.ts";
|
|
4
|
+
import { metricValue, type ActivityMetric } from "../shared/activity.ts";
|
|
4
5
|
import { useMeasuredWidth } from "./measured-width.ts";
|
|
5
6
|
import { mixColor } from "./color-mix.ts";
|
|
7
|
+
import { CHART_MOTION, TEXT, sectionTitle, titleGap } from "./design-tokens.ts";
|
|
8
|
+
import { messagesFor } from "../shared/i18n.ts";
|
|
9
|
+
import { ChartTooltip, InlineEmpty, MetricStepper } from "./ui.tsx";
|
|
6
10
|
|
|
7
11
|
type ThemeColors = {
|
|
8
12
|
accent: string;
|
|
@@ -15,8 +19,8 @@ type ThemeColors = {
|
|
|
15
19
|
/** Hours visible in one viewport; the step follows from the measured width. */
|
|
16
20
|
const VISIBLE_HOURS = 24;
|
|
17
21
|
const STROKE = 2;
|
|
18
|
-
/**
|
|
19
|
-
const
|
|
22
|
+
/** A day label ("Sep 24") plus the right-pinned "Now" must fit, or the label overflows the scroll content. */
|
|
23
|
+
const NOW_LABEL_CLEARANCE = 72;
|
|
20
24
|
|
|
21
25
|
function hourRangeLabel(start: string, locale: string): string {
|
|
22
26
|
const from = new Date(start);
|
|
@@ -33,8 +37,8 @@ function hourRangeLabel(start: string, locale: string): string {
|
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* Filled line series drawn with React Native primitives only (no SVG on the
|
|
36
|
-
* host).
|
|
37
|
-
*
|
|
40
|
+
* host). Clipped `skewY` cells paint the area; rotated strokes and round
|
|
41
|
+
* joints draw one continuous-looking line above it.
|
|
38
42
|
*/
|
|
39
43
|
function AreaSeries({
|
|
40
44
|
values,
|
|
@@ -43,7 +47,6 @@ function AreaSeries({
|
|
|
43
47
|
slot,
|
|
44
48
|
stroke,
|
|
45
49
|
fill,
|
|
46
|
-
flip,
|
|
47
50
|
}: {
|
|
48
51
|
values: readonly number[];
|
|
49
52
|
max: number;
|
|
@@ -51,12 +54,11 @@ function AreaSeries({
|
|
|
51
54
|
slot: number;
|
|
52
55
|
stroke: string;
|
|
53
56
|
fill: string;
|
|
54
|
-
/** Mirror the series below the axis. */
|
|
55
|
-
flip?: boolean;
|
|
56
57
|
}) {
|
|
57
|
-
// Leave room for the
|
|
58
|
+
// Leave room for the line so the peak is never clipped.
|
|
58
59
|
const usable = Math.max(1, height - STROKE - 1);
|
|
59
60
|
const scale = (value: number) => (max > 0 ? (value / max) * usable : 0);
|
|
61
|
+
const heights = values.map(scale);
|
|
60
62
|
|
|
61
63
|
return (
|
|
62
64
|
<View
|
|
@@ -64,17 +66,13 @@ function AreaSeries({
|
|
|
64
66
|
height,
|
|
65
67
|
flexDirection: "row",
|
|
66
68
|
overflow: "hidden",
|
|
67
|
-
transform: flip ? [{ scaleY: -1 }] : undefined,
|
|
68
69
|
}}
|
|
69
70
|
>
|
|
70
|
-
{
|
|
71
|
-
const
|
|
72
|
-
const right = scale(values[index + 1] ?? 0);
|
|
71
|
+
{heights.slice(0, -1).map((left, index) => {
|
|
72
|
+
const right = heights[index + 1] ?? 0;
|
|
73
73
|
// skewY(a) maps y -> y + (x - slot/2)·tan(a), so tan is the segment slope.
|
|
74
74
|
const tan = (left - right) / slot;
|
|
75
75
|
const angle = (Math.atan(tan) * 180) / Math.PI;
|
|
76
|
-
// Vertical band that renders as a STROKE-thick perpendicular line.
|
|
77
|
-
const band = Math.min(MAX_STROKE_BAND, STROKE * Math.hypot(1, tan));
|
|
78
76
|
return (
|
|
79
77
|
<View key={index} style={{ width: slot, height, overflow: "hidden" }}>
|
|
80
78
|
<View
|
|
@@ -82,19 +80,50 @@ function AreaSeries({
|
|
|
82
80
|
position: "absolute",
|
|
83
81
|
left: 0,
|
|
84
82
|
width: slot,
|
|
85
|
-
// Place the sheared top edge on the two hour values
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
height: height * 2 + slot * Math.abs(tan) + band,
|
|
83
|
+
// Place the sheared top edge on the two hour values.
|
|
84
|
+
top: height - left + (slot / 2) * tan,
|
|
85
|
+
height: height * 2 + slot * Math.abs(tan),
|
|
89
86
|
backgroundColor: fill,
|
|
90
|
-
borderTopWidth: band,
|
|
91
|
-
borderTopColor: stroke,
|
|
92
87
|
transform: [{ skewY: `${angle}deg` }],
|
|
93
88
|
}}
|
|
94
89
|
/>
|
|
95
90
|
</View>
|
|
96
91
|
);
|
|
97
92
|
})}
|
|
93
|
+
{heights.slice(0, -1).map((left, index) => {
|
|
94
|
+
const right = heights[index + 1] ?? 0;
|
|
95
|
+
const rise = left - right;
|
|
96
|
+
const length = Math.hypot(slot, rise);
|
|
97
|
+
return (
|
|
98
|
+
<View
|
|
99
|
+
key={`line-${index}`}
|
|
100
|
+
style={{
|
|
101
|
+
position: "absolute",
|
|
102
|
+
left: index * slot + (slot - length) / 2,
|
|
103
|
+
top: height - (left + right) / 2 - STROKE / 2,
|
|
104
|
+
width: length,
|
|
105
|
+
height: STROKE,
|
|
106
|
+
borderRadius: STROKE / 2,
|
|
107
|
+
backgroundColor: stroke,
|
|
108
|
+
transform: [{ rotate: `${(Math.atan2(rise, slot) * 180) / Math.PI}deg` }],
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
{heights.slice(1, -1).map((value, index) => (
|
|
114
|
+
<View
|
|
115
|
+
key={`joint-${index}`}
|
|
116
|
+
style={{
|
|
117
|
+
position: "absolute",
|
|
118
|
+
left: (index + 1) * slot - STROKE / 2,
|
|
119
|
+
top: height - value - STROKE / 2,
|
|
120
|
+
width: STROKE,
|
|
121
|
+
height: STROKE,
|
|
122
|
+
borderRadius: STROKE / 2,
|
|
123
|
+
backgroundColor: stroke,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
))}
|
|
98
127
|
</View>
|
|
99
128
|
);
|
|
100
129
|
}
|
|
@@ -121,10 +150,11 @@ export function HourlyActivityTimeline({
|
|
|
121
150
|
const pinnedRight = useRef(true);
|
|
122
151
|
const [width, widthRef, onWidthLayout] = useMeasuredWidth("global:timeline");
|
|
123
152
|
const [hovered, setHovered] = useState<string | null>(null);
|
|
153
|
+
const [plotTop, setPlotTop] = useState(0);
|
|
154
|
+
const [metric, setMetric] = useState<ActivityMetric>("sessions");
|
|
155
|
+
const m = messagesFor(locale);
|
|
124
156
|
|
|
125
|
-
const
|
|
126
|
-
const bottomHeight = compact ? 22 : 30;
|
|
127
|
-
const plotHeight = topHeight + 1 + bottomHeight;
|
|
157
|
+
const plotHeight = compact ? 67 : 89;
|
|
128
158
|
const gaps = Math.max(1, hours.length - 1);
|
|
129
159
|
const slot = width > 0 ? width / VISIBLE_HOURS : 0;
|
|
130
160
|
const contentWidth = slot > 0 ? gaps * slot : 0;
|
|
@@ -167,17 +197,10 @@ export function HourlyActivityTimeline({
|
|
|
167
197
|
scrollRef.current?.scrollToEnd({ animated: false });
|
|
168
198
|
}, [resetKey]);
|
|
169
199
|
|
|
170
|
-
const {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
messages,
|
|
175
|
-
agents,
|
|
176
|
-
messagePeak: messages.reduce((peak, value) => Math.max(peak, value), 0),
|
|
177
|
-
agentPeak: agents.reduce((peak, value) => Math.max(peak, value), 0),
|
|
178
|
-
total: hours.reduce((sum, hour) => sum + hour.total, 0),
|
|
179
|
-
};
|
|
180
|
-
}, [hours]);
|
|
200
|
+
const { values, peak } = useMemo(() => {
|
|
201
|
+
const values = hours.map((hour) => metricValue(hour, metric));
|
|
202
|
+
return { values, peak: values.reduce((max, value) => Math.max(max, value), 0) };
|
|
203
|
+
}, [hours, metric]);
|
|
181
204
|
|
|
182
205
|
/** Local midnights become axis ticks. */
|
|
183
206
|
const dayTicks = useMemo(
|
|
@@ -197,52 +220,49 @@ export function HourlyActivityTimeline({
|
|
|
197
220
|
|
|
198
221
|
const activeIndex = hours.findIndex((hour) => hour.key === hovered);
|
|
199
222
|
const active = activeIndex >= 0 ? hours[activeIndex] : undefined;
|
|
200
|
-
const readout = active
|
|
201
|
-
? `${hourRangeLabel(active.start, locale)} — ${active.agents} agents · ${active.messages} messages · ${active.skills} skills · ${active.mcp} MCP`
|
|
202
|
-
: `Last ${hours.length} hours · ${total.toLocaleString(locale)} events · peak ${agentPeak} agents/h, ${messagePeak} messages/h`;
|
|
203
223
|
|
|
204
224
|
const fill = mixColor(colors.surface2, colors.accent, 0.22);
|
|
205
|
-
const agentStroke = mixColor(colors.surface2, colors.accent, 0.68);
|
|
206
225
|
// Softened toward the surface so the hover cursor reads grey, not near-black.
|
|
207
226
|
const cursorColor = mixColor(colors.surface2, colors.foregroundMuted, 0.55);
|
|
208
227
|
|
|
228
|
+
const ready = hours.length > 0 && slot > 0;
|
|
229
|
+
const grow = useRef(new Animated.Value(0)).current;
|
|
230
|
+
const revealedRef = useRef(false);
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (!ready) return;
|
|
233
|
+
const first = !revealedRef.current;
|
|
234
|
+
grow.setValue(0);
|
|
235
|
+
const animation = Animated.timing(grow, {
|
|
236
|
+
toValue: 1,
|
|
237
|
+
duration: first ? CHART_MOTION.reveal : CHART_MOTION.refresh,
|
|
238
|
+
easing: Easing.out(Easing.cubic),
|
|
239
|
+
useNativeDriver: false,
|
|
240
|
+
});
|
|
241
|
+
animation.start(() => {
|
|
242
|
+
revealedRef.current = true;
|
|
243
|
+
});
|
|
244
|
+
return () => animation.stop();
|
|
245
|
+
}, [ready, metric, resetKey, grow]);
|
|
246
|
+
|
|
209
247
|
// Stable element identity: hovering must not rebuild ~330 skewed segments.
|
|
210
248
|
const series = useMemo(
|
|
211
249
|
() => (
|
|
212
250
|
<>
|
|
213
|
-
<
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
251
|
+
<Animated.View
|
|
252
|
+
style={{
|
|
253
|
+
// scaleY pivots on the center; the shift pins the plot to its baseline.
|
|
254
|
+
transform: [
|
|
255
|
+
{ translateY: grow.interpolate({ inputRange: [0, 1], outputRange: [plotHeight / 2, 0] }) },
|
|
256
|
+
{ scaleY: grow },
|
|
257
|
+
],
|
|
258
|
+
}}
|
|
259
|
+
>
|
|
260
|
+
<AreaSeries values={values} max={peak} height={plotHeight} slot={slot} stroke={colors.accent} fill={fill} />
|
|
261
|
+
</Animated.View>
|
|
221
262
|
<View style={{ height: 1, backgroundColor: colors.border }} />
|
|
222
|
-
<AreaSeries
|
|
223
|
-
values={agents}
|
|
224
|
-
max={agentPeak}
|
|
225
|
-
height={bottomHeight}
|
|
226
|
-
slot={slot}
|
|
227
|
-
stroke={agentStroke}
|
|
228
|
-
fill={fill}
|
|
229
|
-
flip
|
|
230
|
-
/>
|
|
231
263
|
</>
|
|
232
264
|
),
|
|
233
|
-
[
|
|
234
|
-
messages,
|
|
235
|
-
agents,
|
|
236
|
-
messagePeak,
|
|
237
|
-
agentPeak,
|
|
238
|
-
topHeight,
|
|
239
|
-
bottomHeight,
|
|
240
|
-
slot,
|
|
241
|
-
colors.accent,
|
|
242
|
-
colors.border,
|
|
243
|
-
fill,
|
|
244
|
-
agentStroke,
|
|
245
|
-
],
|
|
265
|
+
[values, peak, plotHeight, slot, colors.accent, colors.border, fill, grow],
|
|
246
266
|
);
|
|
247
267
|
|
|
248
268
|
const hotspots = useMemo(
|
|
@@ -263,7 +283,7 @@ export function HourlyActivityTimeline({
|
|
|
263
283
|
<Pressable
|
|
264
284
|
key={hour.key}
|
|
265
285
|
focusable
|
|
266
|
-
accessibilityLabel={`${hourRangeLabel(hour.start, locale)}: ${hour.agents}
|
|
286
|
+
accessibilityLabel={`${hourRangeLabel(hour.start, locale)}: ${m.units.sessions(hour.agents)}, ${m.units.prompts(hour.messages)}, ${m.units.skills(hour.skills)}, ${m.units.mcp(hour.mcp)}`}
|
|
267
287
|
onHoverIn={() => setHovered(hour.key)}
|
|
268
288
|
onHoverOut={() => setHovered(null)}
|
|
269
289
|
onFocus={() => setHovered(hour.key)}
|
|
@@ -279,13 +299,13 @@ export function HourlyActivityTimeline({
|
|
|
279
299
|
))}
|
|
280
300
|
</View>
|
|
281
301
|
),
|
|
282
|
-
[hours, slot, contentWidth, plotHeight, locale],
|
|
302
|
+
[hours, slot, contentWidth, plotHeight, locale, m],
|
|
283
303
|
);
|
|
284
304
|
|
|
285
305
|
return (
|
|
286
306
|
<View
|
|
287
307
|
ref={widthRef}
|
|
288
|
-
style={{ gap: compact
|
|
308
|
+
style={{ gap: titleGap(compact) }}
|
|
289
309
|
onLayout={onWidthLayout}
|
|
290
310
|
>
|
|
291
311
|
<View
|
|
@@ -297,25 +317,21 @@ export function HourlyActivityTimeline({
|
|
|
297
317
|
gap: 12,
|
|
298
318
|
}}
|
|
299
319
|
>
|
|
300
|
-
<Text style={{ color: colors.foreground
|
|
301
|
-
|
|
320
|
+
<Text style={{ ...sectionTitle(compact), color: colors.foreground }}>
|
|
321
|
+
{m.timeline.title}
|
|
302
322
|
</Text>
|
|
303
|
-
<
|
|
304
|
-
<Text style={{ color: colors.accent, fontSize: 12 }}>▲ messages</Text>
|
|
305
|
-
<Text style={{ color: agentStroke, fontSize: 12 }}>▼ agents</Text>
|
|
306
|
-
</View>
|
|
323
|
+
<MetricStepper value={metric} onChange={setMetric} colors={colors} />
|
|
307
324
|
</View>
|
|
308
325
|
|
|
309
326
|
{hours.length === 0 || slot === 0 ? (
|
|
310
327
|
<View style={{ height: plotHeight, justifyContent: "center" }}>
|
|
311
|
-
<
|
|
312
|
-
{hours.length === 0 ? "No activity yet" : ""}
|
|
313
|
-
</Text>
|
|
328
|
+
{hours.length === 0 ? <InlineEmpty text={m.timeline.empty} color={colors.foregroundMuted} /> : null}
|
|
314
329
|
</View>
|
|
315
330
|
) : (
|
|
316
331
|
<ScrollView
|
|
317
332
|
ref={scrollRef}
|
|
318
333
|
horizontal
|
|
334
|
+
onLayout={(event) => setPlotTop(event.nativeEvent.layout.y)}
|
|
319
335
|
nestedScrollEnabled
|
|
320
336
|
showsHorizontalScrollIndicator={false}
|
|
321
337
|
scrollEventThrottle={16}
|
|
@@ -350,43 +366,60 @@ export function HourlyActivityTimeline({
|
|
|
350
366
|
{hotspots}
|
|
351
367
|
|
|
352
368
|
<View style={{ height: 16, marginTop: 4 }}>
|
|
353
|
-
{dayTicks
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
<Text
|
|
360
|
-
numberOfLines={1}
|
|
361
|
-
style={{ color: colors.foregroundMuted, fontSize: 11, marginTop: 2 }}
|
|
369
|
+
{dayTicks
|
|
370
|
+
.filter((tick) => tick.index * slot <= contentWidth - NOW_LABEL_CLEARANCE)
|
|
371
|
+
.map((tick) => (
|
|
372
|
+
<View
|
|
373
|
+
key={tick.index}
|
|
374
|
+
style={{ position: "absolute", left: tick.index * slot, top: -4 }}
|
|
362
375
|
>
|
|
363
|
-
{
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
376
|
+
<View style={{ width: 1, height: 3, backgroundColor: colors.border }} />
|
|
377
|
+
<Text
|
|
378
|
+
numberOfLines={1}
|
|
379
|
+
style={{ ...TEXT.caption, color: colors.foregroundMuted, marginTop: 2 }}
|
|
380
|
+
>
|
|
381
|
+
{tick.label}
|
|
382
|
+
</Text>
|
|
383
|
+
</View>
|
|
384
|
+
))}
|
|
367
385
|
<Text
|
|
368
386
|
style={{
|
|
369
387
|
position: "absolute",
|
|
370
388
|
right: 0,
|
|
371
389
|
top: 1,
|
|
390
|
+
...TEXT.caption,
|
|
372
391
|
color: colors.foregroundMuted,
|
|
373
|
-
fontSize: 11,
|
|
374
392
|
}}
|
|
375
393
|
>
|
|
376
|
-
|
|
394
|
+
{m.common.now}
|
|
377
395
|
</Text>
|
|
378
396
|
</View>
|
|
379
397
|
</View>
|
|
380
398
|
</ScrollView>
|
|
381
399
|
)}
|
|
382
400
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
401
|
+
{active && slot > 0 ? (
|
|
402
|
+
<ChartTooltip
|
|
403
|
+
anchorX={activeIndex * slot - offsetRef.current}
|
|
404
|
+
anchorY={plotTop}
|
|
405
|
+
containerWidth={width}
|
|
406
|
+
clampTop={false}
|
|
407
|
+
title={hourRangeLabel(active.start, locale)}
|
|
408
|
+
rows={(
|
|
409
|
+
[
|
|
410
|
+
["sessions", m.common.sessions],
|
|
411
|
+
["prompts", m.common.prompts],
|
|
412
|
+
["skills", m.common.skills],
|
|
413
|
+
["mcp", m.common.mcp],
|
|
414
|
+
] as const
|
|
415
|
+
).map(([id, label]) => ({
|
|
416
|
+
label,
|
|
417
|
+
value: metricValue(active, id).toLocaleString(locale),
|
|
418
|
+
color: id === metric ? colors.accent : undefined,
|
|
419
|
+
}))}
|
|
420
|
+
colors={colors}
|
|
421
|
+
/>
|
|
422
|
+
) : null}
|
|
390
423
|
</View>
|
|
391
424
|
);
|
|
392
425
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { isPanelMounted, setPanelMounted, watchPanelPresence } from "./panel-visibility.ts";
|
|
4
|
+
|
|
5
|
+
test("panel presence tracks instances per workspace and notifies on flips only", () => {
|
|
6
|
+
const events: string[] = [];
|
|
7
|
+
const stop = watchPanelPresence((id) => events.push(`${id}:${isPanelMounted(id)}`));
|
|
8
|
+
const a = {};
|
|
9
|
+
const b = {};
|
|
10
|
+
|
|
11
|
+
setPanelMounted("w1", a, true);
|
|
12
|
+
setPanelMounted("w1", b, true);
|
|
13
|
+
setPanelMounted("w1", a, false);
|
|
14
|
+
assert.equal(isPanelMounted("w1"), true);
|
|
15
|
+
setPanelMounted("w1", b, false);
|
|
16
|
+
setPanelMounted("w1", b, false);
|
|
17
|
+
assert.equal(isPanelMounted("w1"), false);
|
|
18
|
+
assert.equal(isPanelMounted("w2"), false);
|
|
19
|
+
assert.deepEqual(events, ["w1:true", "w1:false"]);
|
|
20
|
+
|
|
21
|
+
stop();
|
|
22
|
+
setPanelMounted("w1", a, true);
|
|
23
|
+
assert.deepEqual(events, ["w1:true", "w1:false"]);
|
|
24
|
+
setPanelMounted("w1", a, false);
|
|
25
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which workspaces currently have a mounted Workspace Activity panel (067).
|
|
5
|
+
*
|
|
6
|
+
* Inactive tabs and a collapsed Explorer stay mounted. The host can still
|
|
7
|
+
* evict an inactive tab after its retained-tab limit is reached.
|
|
8
|
+
*/
|
|
9
|
+
const mounted = new Map<string, Set<object>>();
|
|
10
|
+
const listeners = new Set<(workspaceId: string) => void>();
|
|
11
|
+
|
|
12
|
+
export function setPanelMounted(workspaceId: string, instance: object, isMounted: boolean): void {
|
|
13
|
+
const instances = mounted.get(workspaceId);
|
|
14
|
+
const was = instances != null && instances.size > 0;
|
|
15
|
+
if (isMounted) {
|
|
16
|
+
if (instances) instances.add(instance);
|
|
17
|
+
else mounted.set(workspaceId, new Set([instance]));
|
|
18
|
+
} else if (instances) {
|
|
19
|
+
instances.delete(instance);
|
|
20
|
+
if (instances.size === 0) mounted.delete(workspaceId);
|
|
21
|
+
}
|
|
22
|
+
if (was === isPanelMounted(workspaceId)) return;
|
|
23
|
+
for (const listener of listeners) listener(workspaceId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isPanelMounted(workspaceId: string): boolean {
|
|
27
|
+
return (mounted.get(workspaceId)?.size ?? 0) > 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Called with the workspace id whenever its mounted state flips. */
|
|
31
|
+
export function watchPanelPresence(listener: (workspaceId: string) => void): () => void {
|
|
32
|
+
listeners.add(listener);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Registers a panel until unmount or workspace change. */
|
|
39
|
+
export function usePanelPresenceReport(workspaceId: string): void {
|
|
40
|
+
const instance = useRef({}).current;
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setPanelMounted(workspaceId, instance, true);
|
|
43
|
+
return () => setPanelMounted(workspaceId, instance, false);
|
|
44
|
+
}, [workspaceId, instance]);
|
|
45
|
+
}
|