@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
package/shared/insights.test.ts
CHANGED
|
@@ -27,13 +27,15 @@ function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem,
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
describe("buildActivityInsights", () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// 2026-03-07 Sat, 2026-03-09 Mon — Mon carries more volume → Peak weekday Mon.
|
|
31
|
+
const days = [
|
|
32
|
+
{ date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
|
|
33
|
+
{ date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
it("returns the 8 habit / average rows (072)", () => {
|
|
35
37
|
const rows = buildActivityInsights({
|
|
36
|
-
days,
|
|
38
|
+
days: [...days, { date: "2026-03-10", skills: 0, mcp: 1, agents: 0, messages: 0, total: 1 }],
|
|
37
39
|
summary: {
|
|
38
40
|
skills: 2,
|
|
39
41
|
mcp: 3,
|
|
@@ -43,6 +45,8 @@ describe("buildActivityInsights", () => {
|
|
|
43
45
|
chatAgents: 1,
|
|
44
46
|
},
|
|
45
47
|
workspaces: 7,
|
|
48
|
+
averageSessionMs: 18 * 60_000 + 20_000,
|
|
49
|
+
multiTurn: { multiTurnSessions: 2, promptedSessions: 3 },
|
|
46
50
|
locale: "en",
|
|
47
51
|
});
|
|
48
52
|
|
|
@@ -52,48 +56,48 @@ describe("buildActivityInsights", () => {
|
|
|
52
56
|
[
|
|
53
57
|
"Active days",
|
|
54
58
|
"Busiest day",
|
|
59
|
+
"Longest streak",
|
|
60
|
+
"Peak weekday",
|
|
55
61
|
"Workspaces",
|
|
56
|
-
"Messages",
|
|
57
|
-
"Skill calls",
|
|
58
|
-
"MCP calls",
|
|
59
|
-
"Messages per agent",
|
|
60
62
|
"Coding vs chat",
|
|
63
|
+
"Multi-turn sessions",
|
|
64
|
+
"Avg session duration",
|
|
61
65
|
],
|
|
62
66
|
);
|
|
63
|
-
assert.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
assert.equal(rows[5]?.value, "3");
|
|
69
|
-
assert.equal(rows[6]?.value, "2.8");
|
|
70
|
-
// 3 coding / (3+1) active → 75%
|
|
71
|
-
assert.equal(rows[7]?.value, "75% coding");
|
|
67
|
+
assert.deepEqual(
|
|
68
|
+
rows.map((r) => r.value),
|
|
69
|
+
// 3 coding / (3+1) active → 75%; Mar 9–10 streak; 2 of 3 prompted sessions multi-turn.
|
|
70
|
+
["3", "Mar 9 · 10 prompts", "2 days", "Monday", "7", "75% coding", "67%", "18 min"],
|
|
71
|
+
);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it("uses dashes for
|
|
74
|
+
it("uses dashes for empty data and falls back busiest day", () => {
|
|
75
75
|
const rows = buildActivityInsights({
|
|
76
76
|
days: [{ date: "2026-03-08", skills: 3, mcp: 1, agents: 2, messages: 0, total: 4 }],
|
|
77
77
|
summary: { skills: 3, mcp: 1, agents: 2, messages: 0, codingAgents: 0, chatAgents: 0 },
|
|
78
78
|
workspaces: 0,
|
|
79
79
|
locale: "en",
|
|
80
80
|
});
|
|
81
|
-
|
|
82
|
-
assert.equal(
|
|
83
|
-
assert.equal(
|
|
84
|
-
assert.equal(
|
|
85
|
-
|
|
81
|
+
const value = (label: string) => rows.find((r) => r.label === label)?.value;
|
|
82
|
+
assert.equal(value("Busiest day"), "Mar 8 · 4 calls");
|
|
83
|
+
assert.equal(value("Peak weekday"), "Sunday");
|
|
84
|
+
assert.equal(value("Longest streak"), "1 day");
|
|
85
|
+
assert.equal(value("Multi-turn sessions"), "—");
|
|
86
|
+
assert.equal(value("Avg session duration"), "—");
|
|
87
|
+
assert.equal(value("Coding vs chat"), "—");
|
|
88
|
+
assert.equal(value("Workspaces"), "0");
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
const rows = buildActivityInsights({
|
|
90
|
+
const empty = buildActivityInsights({
|
|
89
91
|
days: [],
|
|
90
|
-
summary: { skills: 0, mcp: 0, agents:
|
|
92
|
+
summary: { skills: 0, mcp: 0, agents: 0, messages: 0 },
|
|
91
93
|
workspaces: 0,
|
|
94
|
+
averageSessionMs: null,
|
|
92
95
|
locale: "en",
|
|
93
96
|
});
|
|
94
|
-
assert.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
empty.map((r) => r.value),
|
|
99
|
+
["0", "—", "—", "—", "0", "—", "—", "—"],
|
|
100
|
+
);
|
|
97
101
|
});
|
|
98
102
|
});
|
|
99
103
|
|
|
@@ -101,8 +105,11 @@ describe("buildActivityKpi", () => {
|
|
|
101
105
|
const codex = provider({
|
|
102
106
|
provider: "codex",
|
|
103
107
|
label: "Codex",
|
|
104
|
-
messageCount:
|
|
105
|
-
models: [
|
|
108
|
+
messageCount: 12,
|
|
109
|
+
models: [
|
|
110
|
+
{ model: "gpt-5.4", count: 9 },
|
|
111
|
+
{ model: "gpt-5.4-mini", count: 3 },
|
|
112
|
+
],
|
|
106
113
|
});
|
|
107
114
|
const claude = provider({
|
|
108
115
|
provider: "claude",
|
|
@@ -110,76 +117,108 @@ describe("buildActivityKpi", () => {
|
|
|
110
117
|
messageCount: 4,
|
|
111
118
|
models: [{ model: "opus", count: 4 }],
|
|
112
119
|
});
|
|
113
|
-
|
|
114
|
-
const days = [
|
|
115
|
-
{ date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
|
|
116
|
-
{ date: "2026-03-09", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 },
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
it("leads with top / longest tiles", () => {
|
|
120
|
+
it("shows sessions, prompts and shares (069 / 070 / 072)", () => {
|
|
120
121
|
const rows = buildActivityKpi({
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
sessions: 12345,
|
|
123
|
+
messages: 1605,
|
|
123
124
|
locale: "en",
|
|
124
|
-
longestStreak: 6,
|
|
125
|
-
longestAgent: { durationMs: 277.7 * 3_600_000, active: false },
|
|
126
125
|
providers: [codex, claude],
|
|
126
|
+
allProviders: [codex, claude],
|
|
127
127
|
providerFilter: "all",
|
|
128
128
|
});
|
|
129
129
|
assert.deepEqual(
|
|
130
130
|
rows.map((r) => r.label),
|
|
131
|
-
["
|
|
131
|
+
["Sessions", "Prompts", "Top provider", "Top model"],
|
|
132
132
|
);
|
|
133
|
-
assert.equal(rows[0]?.value, "12
|
|
134
|
-
assert.equal(rows[1]?.value, "
|
|
135
|
-
assert.equal(rows[2]?.value, "Codex");
|
|
136
|
-
|
|
137
|
-
assert.equal(rows[
|
|
138
|
-
assert.equal(rows
|
|
133
|
+
assert.equal(rows[0]?.value, "12,345");
|
|
134
|
+
assert.equal(rows[1]?.value, "1,605");
|
|
135
|
+
assert.equal(rows[2]?.value, "Codex · 75%");
|
|
136
|
+
// gpt-5.4 9 of 16 model messages → 56%
|
|
137
|
+
assert.equal(rows[3]?.value, "Gpt 5.4 · 56%");
|
|
138
|
+
assert.equal(rows.length, 4);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it("
|
|
141
|
+
it("scopes shares to the selected provider", () => {
|
|
142
142
|
const rows = buildActivityKpi({
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
sessions: 0,
|
|
144
|
+
messages: 4,
|
|
145
145
|
locale: "en",
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
providers: [claude],
|
|
147
|
+
allProviders: [codex, claude],
|
|
148
|
+
providerFilter: "claude",
|
|
149
|
+
});
|
|
150
|
+
assert.equal(rows[2]?.value, "Claude · 25%");
|
|
151
|
+
assert.equal(rows[3]?.value, "Opus · 100%");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("tolerates missing data", () => {
|
|
155
|
+
const empty = buildActivityKpi({
|
|
156
|
+
sessions: 0,
|
|
157
|
+
messages: 0,
|
|
158
|
+
locale: "en",
|
|
159
|
+
providers: [],
|
|
160
|
+
allProviders: [],
|
|
149
161
|
providerFilter: "all",
|
|
150
162
|
});
|
|
151
|
-
assert.equal(
|
|
152
|
-
assert.equal(
|
|
163
|
+
assert.equal(empty[0]?.value, "0");
|
|
164
|
+
assert.equal(empty[2]?.value, "—");
|
|
165
|
+
assert.equal(empty[3]?.value, "—");
|
|
153
166
|
});
|
|
154
167
|
|
|
155
|
-
it("
|
|
168
|
+
it("compares each KPI against the preceding seven days", () => {
|
|
169
|
+
const current = [
|
|
170
|
+
provider({ provider: "codex", label: "Codex", agentCount: 10, messageCount: 9, models: [{ model: "gpt-5.4", count: 9 }] }),
|
|
171
|
+
provider({ provider: "claude", label: "Claude", agentCount: 2, messageCount: 1, models: [{ model: "opus", count: 1 }] }),
|
|
172
|
+
];
|
|
173
|
+
const previous = [
|
|
174
|
+
provider({ provider: "codex", label: "Codex", agentCount: 6, messageCount: 4, models: [{ model: "gpt-5.4", count: 4 }] }),
|
|
175
|
+
provider({ provider: "claude", label: "Claude", agentCount: 4, messageCount: 6, models: [{ model: "opus", count: 6 }] }),
|
|
176
|
+
];
|
|
156
177
|
const rows = buildActivityKpi({
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
sessions: 100,
|
|
179
|
+
messages: 160,
|
|
180
|
+
providers: [codex, claude],
|
|
181
|
+
allProviders: [codex, claude],
|
|
182
|
+
providerFilter: "all",
|
|
159
183
|
locale: "en",
|
|
160
|
-
|
|
161
|
-
longestAgent: null,
|
|
162
|
-
providers: [codex],
|
|
163
|
-
providerFilter: "codex",
|
|
184
|
+
comparison: { current, previous },
|
|
164
185
|
});
|
|
165
|
-
assert.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
186
|
+
assert.deepEqual(rows.map((row) => row.comparison?.text), [
|
|
187
|
+
"↑20% vs prev. 7d",
|
|
188
|
+
"→0% vs prev. 7d",
|
|
189
|
+
"Claude prev. 7d",
|
|
190
|
+
"Opus prev. 7d",
|
|
191
|
+
]);
|
|
170
192
|
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
const filtered = buildActivityKpi({
|
|
194
|
+
sessions: 20,
|
|
195
|
+
messages: 30,
|
|
196
|
+
providers: [claude],
|
|
197
|
+
allProviders: [codex, claude],
|
|
198
|
+
providerFilter: "claude",
|
|
174
199
|
locale: "en",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
comparison: { current, previous },
|
|
201
|
+
});
|
|
202
|
+
assert.deepEqual(filtered.map((row) => row.comparison?.text), [
|
|
203
|
+
"↓50% vs prev. 7d",
|
|
204
|
+
"↓83% vs prev. 7d",
|
|
205
|
+
"Claude prev. 7d",
|
|
206
|
+
"Opus prev. 7d",
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("leaves percentage undefined when the preceding window has no baseline", () => {
|
|
211
|
+
const rows = buildActivityKpi({
|
|
212
|
+
sessions: 1,
|
|
213
|
+
messages: 1,
|
|
214
|
+
providers: [codex],
|
|
215
|
+
allProviders: [codex],
|
|
178
216
|
providerFilter: "all",
|
|
217
|
+
comparison: { current: [{ ...codex, agentCount: 1 }], previous: [] },
|
|
179
218
|
});
|
|
180
|
-
assert.equal(
|
|
181
|
-
assert.equal(
|
|
182
|
-
assert.equal(
|
|
183
|
-
assert.equal(
|
|
219
|
+
assert.equal(rows[0]?.comparison?.text, "— vs prev. 7d");
|
|
220
|
+
assert.equal(rows[1]?.comparison?.direction, "unknown");
|
|
221
|
+
assert.equal(rows[2]?.comparison?.text, "— prev. 7d");
|
|
222
|
+
assert.equal(rows[3]?.comparison?.text, "— prev. 7d");
|
|
184
223
|
});
|
|
185
224
|
});
|
package/shared/insights.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ActivityDay, ProviderUsageItem } from "./usage.ts";
|
|
2
|
-
import { isActiveDay } from "./activity.ts";
|
|
2
|
+
import { computeStreaks, isActiveDay } from "./activity.ts";
|
|
3
3
|
import { formatCount, formatDisplayName, formatDuration } from "./format.ts";
|
|
4
|
+
import { messagesFor } from "./i18n.ts";
|
|
4
5
|
|
|
5
6
|
export type InsightRow = { label: string; value: string };
|
|
7
|
+
export type KpiComparison = { text: string; direction: "up" | "down" | "flat" | "unknown" };
|
|
8
|
+
export type KpiRow = InsightRow & { comparison?: KpiComparison };
|
|
6
9
|
|
|
7
10
|
export type InsightSummary = {
|
|
8
11
|
skills: number;
|
|
@@ -18,13 +21,6 @@ export type InsightSummary = {
|
|
|
18
21
|
/** Shared cap for Activity insights and Most used skills / MCP / models. */
|
|
19
22
|
export const ACTIVITY_LIST_LIMIT = 8;
|
|
20
23
|
|
|
21
|
-
function formatRatio(numerator: number, denominator: number): string {
|
|
22
|
-
if (denominator <= 0) return "—";
|
|
23
|
-
const value = numerator / denominator;
|
|
24
|
-
if (Number.isInteger(value)) return String(value);
|
|
25
|
-
return value.toFixed(1).replace(/\.0$/, "");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
24
|
function formatDayLabel(dateKey: string, locale: string): string {
|
|
29
25
|
const [y, m, d] = dateKey.split("-").map(Number);
|
|
30
26
|
if (!y || !m || !d) return dateKey;
|
|
@@ -66,35 +62,49 @@ function pickBusiestDay(days: readonly ActivityDay[]): ActivityDay | null {
|
|
|
66
62
|
|
|
67
63
|
function formatBusiest(day: ActivityDay, locale: string): string {
|
|
68
64
|
const label = formatDayLabel(day.date, locale);
|
|
69
|
-
|
|
65
|
+
const { units } = messagesFor(locale);
|
|
66
|
+
if (day.messages > 0) return `${label} · ${units.prompts(day.messages)}`;
|
|
70
67
|
const calls = day.skills + day.mcp;
|
|
71
|
-
if (calls > 0) return `${label} · ${calls}
|
|
72
|
-
if (day.agents > 0) return `${label} · ${day.agents}
|
|
68
|
+
if (calls > 0) return `${label} · ${units.calls(calls)}`;
|
|
69
|
+
if (day.agents > 0) return `${label} · ${units.sessions(day.agents)}`;
|
|
73
70
|
return label;
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
/**
|
|
77
|
-
function
|
|
73
|
+
/** `label · pct%`; `—` when there is no label or no denominator (069). */
|
|
74
|
+
function withShare(label: string | undefined, count: number, total: number): string {
|
|
75
|
+
if (!label || total <= 0) return "—";
|
|
76
|
+
return `${label} · ${Math.round((count / total) * 100)}%`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Messages-weighted top provider (050) with its share of all providers' messages
|
|
81
|
+
* (069). A selected provider is shown with its own share.
|
|
82
|
+
*/
|
|
83
|
+
function topProviderStats(
|
|
78
84
|
providers: readonly ProviderUsageItem[],
|
|
85
|
+
allProviders: readonly ProviderUsageItem[],
|
|
79
86
|
providerFilter: string,
|
|
80
|
-
): string {
|
|
87
|
+
): { value: string; label: string | undefined } {
|
|
88
|
+
const total = allProviders.reduce((sum, p) => sum + p.messageCount, 0);
|
|
81
89
|
if (providerFilter !== "all") {
|
|
82
|
-
|
|
90
|
+
const selected = providers.find((p) => p.provider === providerFilter);
|
|
91
|
+
return { value: withShare(selected?.label, selected?.messageCount ?? 0, total), label: selected && selected.messageCount > 0 ? selected.label : undefined };
|
|
83
92
|
}
|
|
84
93
|
const ranked = [...providers]
|
|
85
94
|
.filter((p) => p.messageCount > 0)
|
|
86
95
|
.sort(
|
|
87
96
|
(a, b) =>
|
|
88
97
|
b.messageCount - a.messageCount || a.provider.localeCompare(b.provider),
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
);
|
|
99
|
+
const top = ranked[0];
|
|
100
|
+
return { value: withShare(top?.label, top?.messageCount ?? 0, total), label: top?.label };
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
/** Messages-weighted top model (050)
|
|
94
|
-
function
|
|
103
|
+
/** Messages-weighted top model (050) with its share of in-filter model messages (069). */
|
|
104
|
+
function topModelStats(
|
|
95
105
|
providers: readonly ProviderUsageItem[],
|
|
96
106
|
providerFilter: string,
|
|
97
|
-
): string {
|
|
107
|
+
): { value: string; label: string | undefined } {
|
|
98
108
|
const map = new Map<string, number>();
|
|
99
109
|
const source =
|
|
100
110
|
providerFilter === "all"
|
|
@@ -109,19 +119,34 @@ function topModelValue(
|
|
|
109
119
|
(a, b) => b[1] - a[1] || a[0].localeCompare(b[0]),
|
|
110
120
|
);
|
|
111
121
|
const top = ranked[0];
|
|
112
|
-
if (!top || top[1] <= 0) return "—";
|
|
113
|
-
|
|
122
|
+
if (!top || top[1] <= 0) return { value: "—", label: undefined };
|
|
123
|
+
const total = ranked.reduce((sum, [, count]) => sum + count, 0);
|
|
124
|
+
const label = formatDisplayName(top[0]);
|
|
125
|
+
return { value: withShare(label, top[1], total), label };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function comparison(current: number, previous: number, locale: string): KpiComparison {
|
|
129
|
+
const suffix = messagesFor(locale).kpi.previous7Days;
|
|
130
|
+
if (previous === 0 && current > 0) return { text: `— ${suffix}`, direction: "unknown" };
|
|
131
|
+
const change = previous === 0 ? 0 : Math.round(((current - previous) / previous) * 100);
|
|
132
|
+
const direction = change > 0 ? "up" : change < 0 ? "down" : "flat";
|
|
133
|
+
const arrow = direction === "up" ? "↑" : direction === "down" ? "↓" : "→";
|
|
134
|
+
return { text: `${arrow}${Math.abs(change).toLocaleString(locale)}% ${suffix}`, direction };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function previousLeader(label: string | undefined, locale: string): KpiComparison {
|
|
138
|
+
return { text: `${label ?? "—"} ${messagesFor(locale).kpi.previous7DaysBare}`, direction: "unknown" };
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
/** Share of active agents that are coding (018); empty creations excluded. */
|
|
117
|
-
function codingVsChatValue(codingAgents: number, chatAgents: number): string {
|
|
142
|
+
function codingVsChatValue(codingAgents: number, chatAgents: number, locale: string): string {
|
|
118
143
|
const total = codingAgents + chatAgents;
|
|
119
144
|
if (total <= 0) return "—";
|
|
120
145
|
const pct = Math.round((codingAgents / total) * 100);
|
|
121
|
-
return
|
|
146
|
+
return messagesFor(locale).insights.codingShare(pct);
|
|
122
147
|
}
|
|
123
148
|
|
|
124
|
-
/** Weekday with the highest activity volume among active days. */
|
|
149
|
+
/** Weekday with the highest activity volume among active days (full name, 072). */
|
|
125
150
|
function peakWeekdayValue(days: readonly ActivityDay[], locale: string): string {
|
|
126
151
|
const volumes = [0, 0, 0, 0, 0, 0, 0];
|
|
127
152
|
for (const day of days) {
|
|
@@ -139,83 +164,119 @@ function peakWeekdayValue(days: readonly ActivityDay[], locale: string): string
|
|
|
139
164
|
}
|
|
140
165
|
}
|
|
141
166
|
if (bestDow < 0 || bestVol <= 0) return "—";
|
|
142
|
-
// 2026-03-08 was a Sunday — use a known Sunday + offset for locale
|
|
167
|
+
// 2026-03-08 was a Sunday — use a known Sunday + offset for the locale name.
|
|
143
168
|
const probe = new Date(2026, 2, 8 + bestDow);
|
|
144
|
-
return probe.toLocaleDateString(locale, { weekday: "
|
|
169
|
+
return probe.toLocaleDateString(locale, { weekday: "long" });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Share of prompted sessions with ≥2 prompts (072); empty creations excluded. */
|
|
173
|
+
function multiTurnValue(
|
|
174
|
+
multiTurn: { multiTurnSessions: number; promptedSessions: number } | null,
|
|
175
|
+
): string {
|
|
176
|
+
if (!multiTurn || multiTurn.promptedSessions <= 0) return "—";
|
|
177
|
+
return `${Math.round((multiTurn.multiTurnSessions / multiTurn.promptedSessions) * 100)}%`;
|
|
145
178
|
}
|
|
146
179
|
|
|
147
180
|
/**
|
|
148
|
-
* Fixed 8-row insights:
|
|
149
|
-
*
|
|
181
|
+
* Fixed 8-row insights (072 / 080): habit (active days, busiest day, streak,
|
|
182
|
+
* peak weekday, workspaces, coding share) → session shape (multi-turn share,
|
|
183
|
+
* engaged time).
|
|
150
184
|
*/
|
|
151
185
|
export function buildActivityInsights(input: {
|
|
152
186
|
days: readonly ActivityDay[];
|
|
153
187
|
summary: InsightSummary;
|
|
154
|
-
/** Distinct workspaces among
|
|
188
|
+
/** Distinct workspaces among sessions (011). */
|
|
155
189
|
workspaces: number;
|
|
190
|
+
/** Mean engaged time per session from `usage.agent-lifetime` (072). */
|
|
191
|
+
averageSessionMs?: number | null;
|
|
192
|
+
/** Sessions with ≥2 / ≥1 prompts from `usage.agent-lifetime` (072). */
|
|
193
|
+
multiTurn?: { multiTurnSessions: number; promptedSessions: number } | null;
|
|
156
194
|
locale?: string;
|
|
195
|
+
today?: Date;
|
|
157
196
|
}): InsightRow[] {
|
|
158
197
|
const locale = input.locale ?? "en";
|
|
159
|
-
const activeDays = input.days.filter(isActiveDay).length;
|
|
160
198
|
const busiest = pickBusiestDay(input.days);
|
|
199
|
+
const activeDays = input.days.filter(isActiveDay).length;
|
|
200
|
+
const { longest } = computeStreaks(input.days, input.today);
|
|
161
201
|
const codingAgents = input.summary.codingAgents ?? 0;
|
|
162
202
|
const chatAgents = input.summary.chatAgents ?? 0;
|
|
203
|
+
const { insights: m, units } = messagesFor(locale);
|
|
204
|
+
const averageSessionMs = input.averageSessionMs;
|
|
163
205
|
|
|
164
206
|
return [
|
|
165
|
-
{ label:
|
|
207
|
+
{ label: m.activeDays, value: activeDays.toLocaleString(locale) },
|
|
166
208
|
{
|
|
167
|
-
label:
|
|
209
|
+
label: m.busiestDay,
|
|
168
210
|
value: busiest ? formatBusiest(busiest, locale) : "—",
|
|
169
211
|
},
|
|
170
|
-
{ label:
|
|
171
|
-
{ label:
|
|
172
|
-
{ label:
|
|
173
|
-
{ label: "MCP calls", value: input.summary.mcp.toLocaleString(locale) },
|
|
212
|
+
{ label: m.longestStreak, value: longest > 0 ? units.days(longest) : "—" },
|
|
213
|
+
{ label: m.peakWeekday, value: peakWeekdayValue(input.days, locale) },
|
|
214
|
+
{ label: m.workspaces, value: formatCount(input.workspaces) },
|
|
174
215
|
{
|
|
175
|
-
label:
|
|
176
|
-
value:
|
|
216
|
+
label: m.codingVsChat,
|
|
217
|
+
value: codingVsChatValue(codingAgents, chatAgents, locale),
|
|
177
218
|
},
|
|
219
|
+
{ label: m.multiTurnSessions, value: multiTurnValue(input.multiTurn ?? null) },
|
|
178
220
|
{
|
|
179
|
-
label:
|
|
180
|
-
value:
|
|
221
|
+
label: m.avgSessionDuration,
|
|
222
|
+
value: averageSessionMs == null ? "—" : formatDuration(averageSessionMs, locale),
|
|
181
223
|
},
|
|
182
224
|
];
|
|
183
225
|
}
|
|
184
226
|
|
|
185
227
|
/**
|
|
186
|
-
* Fixed
|
|
187
|
-
*
|
|
228
|
+
* Fixed 4-tile KPI row (069 / 070 / 072): sessions, prompts, top provider ·
|
|
229
|
+
* share, top model · share. Active days lives in Insights.
|
|
188
230
|
*/
|
|
189
231
|
export function buildActivityKpi(input: {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
days: readonly ActivityDay[];
|
|
232
|
+
sessions: number;
|
|
233
|
+
messages: number;
|
|
193
234
|
locale?: string;
|
|
194
|
-
|
|
195
|
-
/** Longest created→(archived | now) span from the registry (049 / 051). */
|
|
196
|
-
longestAgent: { durationMs: number; active: boolean } | null;
|
|
235
|
+
/** Provider rows after the provider filter. */
|
|
197
236
|
providers: readonly ProviderUsageItem[];
|
|
237
|
+
/** Every provider; denominator of the top-provider share. */
|
|
238
|
+
allProviders: readonly ProviderUsageItem[];
|
|
198
239
|
providerFilter: string;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
240
|
+
/** Two adjacent seven-day windows, when the comparison query has loaded. */
|
|
241
|
+
comparison?: {
|
|
242
|
+
current: readonly ProviderUsageItem[];
|
|
243
|
+
previous: readonly ProviderUsageItem[];
|
|
244
|
+
};
|
|
245
|
+
}): KpiRow[] {
|
|
246
|
+
const locale = input.locale ?? "en";
|
|
247
|
+
const m = messagesFor(locale).kpi;
|
|
248
|
+
const topProvider = topProviderStats(input.providers, input.allProviders, input.providerFilter);
|
|
249
|
+
const topModel = topModelStats(input.providers, input.providerFilter);
|
|
250
|
+
const current = input.comparison?.current ?? [];
|
|
251
|
+
const previous = input.comparison?.previous ?? [];
|
|
252
|
+
const previousProvider = topProviderStats(previous, previous, input.providerFilter);
|
|
253
|
+
const previousModel = topModelStats(previous, input.providerFilter);
|
|
254
|
+
const count = (items: readonly ProviderUsageItem[], field: "agentCount" | "messageCount") =>
|
|
255
|
+
items.reduce(
|
|
256
|
+
(sum, item) => sum + (input.providerFilter === "all" || item.provider === input.providerFilter ? item[field] : 0),
|
|
257
|
+
0,
|
|
258
|
+
);
|
|
259
|
+
const trend = input.comparison;
|
|
202
260
|
return [
|
|
203
|
-
{ label: "Agents", value: formatCount(input.agents) },
|
|
204
261
|
{
|
|
205
|
-
label:
|
|
206
|
-
value:
|
|
207
|
-
|
|
208
|
-
|
|
262
|
+
label: m.sessions,
|
|
263
|
+
value: input.sessions.toLocaleString(locale),
|
|
264
|
+
comparison: trend ? comparison(count(current, "agentCount"), count(previous, "agentCount"), locale) : undefined,
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
label: m.prompts,
|
|
268
|
+
value: input.messages.toLocaleString(locale),
|
|
269
|
+
comparison: trend ? comparison(count(current, "messageCount"), count(previous, "messageCount"), locale) : undefined,
|
|
209
270
|
},
|
|
210
271
|
{
|
|
211
|
-
label:
|
|
212
|
-
value:
|
|
272
|
+
label: m.topProvider,
|
|
273
|
+
value: topProvider.value,
|
|
274
|
+
comparison: trend ? previousLeader(previousProvider.label, locale) : undefined,
|
|
213
275
|
},
|
|
214
276
|
{
|
|
215
|
-
label:
|
|
216
|
-
value:
|
|
277
|
+
label: m.topModel,
|
|
278
|
+
value: topModel.value,
|
|
279
|
+
comparison: trend ? previousLeader(previousModel.label, locale) : undefined,
|
|
217
280
|
},
|
|
218
|
-
{ label: "Peak weekday", value: peakWeekdayValue(input.days, input.locale ?? "en") },
|
|
219
|
-
{ label: "Longest streak", value: `${streak} day${streak === 1 ? "" : "s"}` },
|
|
220
281
|
];
|
|
221
282
|
}
|