@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.
- package/CHANGELOG.md +50 -1
- package/README.md +18 -11
- package/client/activity-heatmap.tsx +115 -74
- package/client/agent-creations.tsx +100 -90
- package/client/attention-pill.tsx +17 -6
- package/client/attention-popover.tsx +19 -23
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +180 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +243 -268
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +153 -103
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +94 -111
- package/client/pill.tsx +1 -1
- package/client/provider-dropdown.tsx +134 -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 +294 -0
- package/client/sidebar-item.tsx +15 -0
- package/client/ui.tsx +351 -0
- package/client/usage-popover.tsx +72 -137
- 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 +28 -28
- package/client/workspace/agents-section.tsx +42 -57
- package/client/workspace/constants.ts +8 -6
- package/client/workspace/display-menu.tsx +6 -5
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +96 -104
- package/client/workspace/rank-section.tsx +40 -65
- package/client/workspace/running-indicator.tsx +1 -1
- package/client/workspace/terminals-section.tsx +24 -12
- package/index.client.tsx +53 -31
- package/index.server.ts +55 -73
- package/package.json +3 -3
- 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/host-types.ts +6 -6
- 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/server/turn-ingest.test.ts +180 -0
- package/server/turn-ingest.ts +71 -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 +125 -64
- 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,13 @@ 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
|
+
// Keep the outgoing metric visible until its plot reaches the baseline.
|
|
156
|
+
const [displayedMetric, setDisplayedMetric] = useState<ActivityMetric>("sessions");
|
|
157
|
+
const m = messagesFor(locale);
|
|
124
158
|
|
|
125
|
-
const
|
|
126
|
-
const bottomHeight = compact ? 22 : 30;
|
|
127
|
-
const plotHeight = topHeight + 1 + bottomHeight;
|
|
159
|
+
const plotHeight = compact ? 67 : 89;
|
|
128
160
|
const gaps = Math.max(1, hours.length - 1);
|
|
129
161
|
const slot = width > 0 ? width / VISIBLE_HOURS : 0;
|
|
130
162
|
const contentWidth = slot > 0 ? gaps * slot : 0;
|
|
@@ -167,17 +199,10 @@ export function HourlyActivityTimeline({
|
|
|
167
199
|
scrollRef.current?.scrollToEnd({ animated: false });
|
|
168
200
|
}, [resetKey]);
|
|
169
201
|
|
|
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]);
|
|
202
|
+
const { values, peak } = useMemo(() => {
|
|
203
|
+
const values = hours.map((hour) => metricValue(hour, displayedMetric));
|
|
204
|
+
return { values, peak: values.reduce((max, value) => Math.max(max, value), 0) };
|
|
205
|
+
}, [hours, displayedMetric]);
|
|
181
206
|
|
|
182
207
|
/** Local midnights become axis ticks. */
|
|
183
208
|
const dayTicks = useMemo(
|
|
@@ -197,52 +222,64 @@ export function HourlyActivityTimeline({
|
|
|
197
222
|
|
|
198
223
|
const activeIndex = hours.findIndex((hour) => hour.key === hovered);
|
|
199
224
|
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
225
|
|
|
204
226
|
const fill = mixColor(colors.surface2, colors.accent, 0.22);
|
|
205
|
-
const agentStroke = mixColor(colors.surface2, colors.accent, 0.68);
|
|
206
227
|
// Softened toward the surface so the hover cursor reads grey, not near-black.
|
|
207
228
|
const cursorColor = mixColor(colors.surface2, colors.foregroundMuted, 0.55);
|
|
208
229
|
|
|
230
|
+
const ready = hours.length > 0 && slot > 0;
|
|
231
|
+
const grow = useRef(new Animated.Value(0)).current;
|
|
232
|
+
const revealedRef = useRef(false);
|
|
233
|
+
const previousResetKey = useRef(resetKey);
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
if (!ready) {
|
|
236
|
+
grow.setValue(0);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const providerChanged = previousResetKey.current !== resetKey;
|
|
240
|
+
previousResetKey.current = resetKey;
|
|
241
|
+
let cancelled = false;
|
|
242
|
+
const first = !revealedRef.current;
|
|
243
|
+
const exiting = metric !== displayedMetric;
|
|
244
|
+
if (providerChanged && !exiting) grow.setValue(0);
|
|
245
|
+
const animation = Animated.timing(grow, {
|
|
246
|
+
toValue: exiting ? 0 : 1,
|
|
247
|
+
duration: exiting
|
|
248
|
+
? CHART_MOTION.discloseClose
|
|
249
|
+
: first ? CHART_MOTION.reveal : CHART_MOTION.refresh,
|
|
250
|
+
easing: Easing.out(Easing.cubic),
|
|
251
|
+
useNativeDriver: true,
|
|
252
|
+
});
|
|
253
|
+
animation.start(({ finished }) => {
|
|
254
|
+
if (cancelled || !finished) return;
|
|
255
|
+
revealedRef.current = true;
|
|
256
|
+
if (exiting) setDisplayedMetric(metric);
|
|
257
|
+
});
|
|
258
|
+
return () => {
|
|
259
|
+
cancelled = true;
|
|
260
|
+
animation.stop();
|
|
261
|
+
};
|
|
262
|
+
}, [ready, metric, displayedMetric, resetKey, grow]);
|
|
263
|
+
|
|
209
264
|
// Stable element identity: hovering must not rebuild ~330 skewed segments.
|
|
210
265
|
const series = useMemo(
|
|
211
266
|
() => (
|
|
212
267
|
<>
|
|
213
|
-
<
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
268
|
+
<Animated.View
|
|
269
|
+
style={{
|
|
270
|
+
// scaleY pivots on the center; the shift pins the plot to its baseline.
|
|
271
|
+
transform: [
|
|
272
|
+
{ translateY: grow.interpolate({ inputRange: [0, 1], outputRange: [plotHeight / 2, 0] }) },
|
|
273
|
+
{ scaleY: grow },
|
|
274
|
+
],
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
<AreaSeries values={values} max={peak} height={plotHeight} slot={slot} stroke={colors.accent} fill={fill} />
|
|
278
|
+
</Animated.View>
|
|
221
279
|
<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
280
|
</>
|
|
232
281
|
),
|
|
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
|
-
],
|
|
282
|
+
[values, peak, plotHeight, slot, colors.accent, colors.border, fill, grow],
|
|
246
283
|
);
|
|
247
284
|
|
|
248
285
|
const hotspots = useMemo(
|
|
@@ -263,7 +300,7 @@ export function HourlyActivityTimeline({
|
|
|
263
300
|
<Pressable
|
|
264
301
|
key={hour.key}
|
|
265
302
|
focusable
|
|
266
|
-
accessibilityLabel={`${hourRangeLabel(hour.start, locale)}: ${hour.agents}
|
|
303
|
+
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
304
|
onHoverIn={() => setHovered(hour.key)}
|
|
268
305
|
onHoverOut={() => setHovered(null)}
|
|
269
306
|
onFocus={() => setHovered(hour.key)}
|
|
@@ -279,13 +316,13 @@ export function HourlyActivityTimeline({
|
|
|
279
316
|
))}
|
|
280
317
|
</View>
|
|
281
318
|
),
|
|
282
|
-
[hours, slot, contentWidth, plotHeight, locale],
|
|
319
|
+
[hours, slot, contentWidth, plotHeight, locale, m],
|
|
283
320
|
);
|
|
284
321
|
|
|
285
322
|
return (
|
|
286
323
|
<View
|
|
287
324
|
ref={widthRef}
|
|
288
|
-
style={{ gap: compact
|
|
325
|
+
style={{ gap: titleGap(compact) }}
|
|
289
326
|
onLayout={onWidthLayout}
|
|
290
327
|
>
|
|
291
328
|
<View
|
|
@@ -297,25 +334,21 @@ export function HourlyActivityTimeline({
|
|
|
297
334
|
gap: 12,
|
|
298
335
|
}}
|
|
299
336
|
>
|
|
300
|
-
<Text style={{ color: colors.foreground
|
|
301
|
-
|
|
337
|
+
<Text style={{ ...sectionTitle(compact), color: colors.foreground }}>
|
|
338
|
+
{m.timeline.title}
|
|
302
339
|
</Text>
|
|
303
|
-
<
|
|
304
|
-
<Text style={{ color: colors.accent, fontSize: 12 }}>▲ messages</Text>
|
|
305
|
-
<Text style={{ color: agentStroke, fontSize: 12 }}>▼ agents</Text>
|
|
306
|
-
</View>
|
|
340
|
+
<MetricStepper value={metric} onChange={setMetric} colors={colors} />
|
|
307
341
|
</View>
|
|
308
342
|
|
|
309
343
|
{hours.length === 0 || slot === 0 ? (
|
|
310
344
|
<View style={{ height: plotHeight, justifyContent: "center" }}>
|
|
311
|
-
<
|
|
312
|
-
{hours.length === 0 ? "No activity yet" : ""}
|
|
313
|
-
</Text>
|
|
345
|
+
{hours.length === 0 ? <InlineEmpty text={m.timeline.empty} color={colors.foregroundMuted} /> : null}
|
|
314
346
|
</View>
|
|
315
347
|
) : (
|
|
316
348
|
<ScrollView
|
|
317
349
|
ref={scrollRef}
|
|
318
350
|
horizontal
|
|
351
|
+
onLayout={(event) => setPlotTop(event.nativeEvent.layout.y)}
|
|
319
352
|
nestedScrollEnabled
|
|
320
353
|
showsHorizontalScrollIndicator={false}
|
|
321
354
|
scrollEventThrottle={16}
|
|
@@ -350,43 +383,60 @@ export function HourlyActivityTimeline({
|
|
|
350
383
|
{hotspots}
|
|
351
384
|
|
|
352
385
|
<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 }}
|
|
386
|
+
{dayTicks
|
|
387
|
+
.filter((tick) => tick.index * slot <= contentWidth - NOW_LABEL_CLEARANCE)
|
|
388
|
+
.map((tick) => (
|
|
389
|
+
<View
|
|
390
|
+
key={tick.index}
|
|
391
|
+
style={{ position: "absolute", left: tick.index * slot, top: -4 }}
|
|
362
392
|
>
|
|
363
|
-
{
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
393
|
+
<View style={{ width: 1, height: 3, backgroundColor: colors.border }} />
|
|
394
|
+
<Text
|
|
395
|
+
numberOfLines={1}
|
|
396
|
+
style={{ ...TEXT.caption, color: colors.foregroundMuted, marginTop: 2 }}
|
|
397
|
+
>
|
|
398
|
+
{tick.label}
|
|
399
|
+
</Text>
|
|
400
|
+
</View>
|
|
401
|
+
))}
|
|
367
402
|
<Text
|
|
368
403
|
style={{
|
|
369
404
|
position: "absolute",
|
|
370
405
|
right: 0,
|
|
371
406
|
top: 1,
|
|
407
|
+
...TEXT.caption,
|
|
372
408
|
color: colors.foregroundMuted,
|
|
373
|
-
fontSize: 11,
|
|
374
409
|
}}
|
|
375
410
|
>
|
|
376
|
-
|
|
411
|
+
{m.common.now}
|
|
377
412
|
</Text>
|
|
378
413
|
</View>
|
|
379
414
|
</View>
|
|
380
415
|
</ScrollView>
|
|
381
416
|
)}
|
|
382
417
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
418
|
+
{active && slot > 0 ? (
|
|
419
|
+
<ChartTooltip
|
|
420
|
+
anchorX={activeIndex * slot - offsetRef.current}
|
|
421
|
+
anchorY={plotTop}
|
|
422
|
+
containerWidth={width}
|
|
423
|
+
clampTop={false}
|
|
424
|
+
title={hourRangeLabel(active.start, locale)}
|
|
425
|
+
rows={(
|
|
426
|
+
[
|
|
427
|
+
["sessions", m.common.sessions],
|
|
428
|
+
["prompts", m.common.prompts],
|
|
429
|
+
["skills", m.common.skills],
|
|
430
|
+
["mcp", m.common.mcp],
|
|
431
|
+
] as const
|
|
432
|
+
).map(([id, label]) => ({
|
|
433
|
+
label,
|
|
434
|
+
value: metricValue(active, id).toLocaleString(locale),
|
|
435
|
+
color: id === metric ? colors.accent : undefined,
|
|
436
|
+
}))}
|
|
437
|
+
colors={colors}
|
|
438
|
+
/>
|
|
439
|
+
) : null}
|
|
390
440
|
</View>
|
|
391
441
|
);
|
|
392
442
|
}
|
|
@@ -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
|
+
}
|