@koinzhang/paseo-plugin-activity 0.5.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 +78 -1
- package/README.md +15 -8
- package/client/activity-heatmap.tsx +126 -93
- package/client/agent-creations.tsx +216 -0
- package/client/attention-pill.tsx +16 -5
- package/client/attention-popover.tsx +19 -23
- package/client/color-mix.test.ts +27 -0
- package/client/color-mix.ts +38 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +168 -0
- package/client/fit-text.test.ts +41 -0
- package/client/fit-text.ts +33 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +316 -275
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +425 -0
- package/client/measured-width.ts +72 -0
- 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/range.test.ts +44 -0
- package/client/range.ts +14 -0
- package/client/rank-color.test.ts +108 -14
- package/client/rank-color.ts +261 -48
- 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 +137 -8
- 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 +176 -104
- package/client/workspace/rank-section.tsx +157 -44
- package/client/workspace/terminals-section.tsx +13 -9
- package/index.client.tsx +40 -20
- package/index.server.ts +63 -31
- package/package.json +2 -2
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.test.ts +43 -0
- package/server/background-sync.ts +43 -4
- package/server/handlers-query.test.ts +252 -1
- package/server/handlers.ts +174 -13
- 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 +159 -6
- package/shared/activity.ts +140 -5
- package/shared/classify.test.ts +1 -0
- package/shared/classify.ts +4 -1
- package/shared/explorer-agent-display.test.ts +61 -0
- package/shared/explorer-agent-display.ts +21 -2
- package/shared/format.test.ts +28 -3
- package/shared/format.ts +25 -2
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +162 -80
- package/shared/insights.ts +136 -61
- package/shared/usage.test.ts +330 -0
- package/shared/usage.ts +471 -0
package/shared/activity.test.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
activityLevel,
|
|
5
|
+
buildActivityCalendar,
|
|
6
|
+
buildAgentCreationBuckets,
|
|
7
|
+
buildDailyMetricBuckets,
|
|
8
|
+
computeStreaks,
|
|
9
|
+
metricValue,
|
|
10
|
+
stepMetric,
|
|
11
|
+
rankCreationProviders,
|
|
12
|
+
stackCreationProviders,
|
|
13
|
+
} from "./activity.ts";
|
|
4
14
|
|
|
5
15
|
const days = [
|
|
6
16
|
{ date: "2026-03-07", skills: 2, mcp: 1, agents: 2, messages: 4, total: 9 },
|
|
@@ -63,18 +73,65 @@ describe("activity calendar", () => {
|
|
|
63
73
|
assert.equal(weeklyCell?.agents, 1);
|
|
64
74
|
assert.equal(weeklyCell?.messages, 3);
|
|
65
75
|
});
|
|
66
|
-
it("
|
|
76
|
+
it("aligns rows to weekdays across day, month, year, leap day and DST boundaries (058)", () => {
|
|
67
77
|
const previous = process.env.TZ;
|
|
68
78
|
process.env.TZ = "America/New_York";
|
|
69
79
|
try {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
for (const [year, month, day] of [
|
|
81
|
+
[2026, 8, 19], [2026, 8, 20], [2026, 8, 21], // Saturday → Sunday → Monday
|
|
82
|
+
[2026, 8, 30], [2026, 9, 1],
|
|
83
|
+
[2026, 11, 31], [2027, 0, 1],
|
|
84
|
+
[2024, 1, 29], [2024, 2, 1],
|
|
85
|
+
[2026, 2, 8], [2026, 2, 9], [2026, 10, 1], [2026, 10, 2],
|
|
86
|
+
]) {
|
|
87
|
+
const end = new Date(year!, month!, day!);
|
|
88
|
+
const label = `${year}-${month! + 1}-${day}`;
|
|
89
|
+
for (const mode of ["daily", "weekly", "cumulative"] as const) {
|
|
90
|
+
const result = buildActivityCalendar(days, mode, undefined, end);
|
|
91
|
+
const cells = result.weeks.flat();
|
|
92
|
+
assert.equal(result.weeks.length, 52, label);
|
|
93
|
+
assert.ok(result.weeks.every(week => week.length === 7), label);
|
|
94
|
+
assert.equal(new Set(cells.map(cell => cell.key)).size, 364, label);
|
|
95
|
+
assert.ok(cells.every(cell => !cell.excluded), label);
|
|
96
|
+
// Row index === weekday, Sunday first.
|
|
97
|
+
for (const week of result.weeks) {
|
|
98
|
+
week.forEach((cell, row) => {
|
|
99
|
+
const [y, m, d] = cell.key.split("-").map(Number);
|
|
100
|
+
assert.equal(new Date(y!, m! - 1, d!).getDay(), row, `${label} ${cell.key}`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Visible days are contiguous and end on today; the rest of the last column is future.
|
|
104
|
+
const visible = cells.filter(cell => !cell.future);
|
|
105
|
+
assert.equal(visible.length, cells.length - (6 - end.getDay()), label);
|
|
106
|
+
const expected = new Date(end);
|
|
107
|
+
for (let i = visible.length - 1; i >= 0; i--) {
|
|
108
|
+
const key = `${expected.getFullYear()}-${String(expected.getMonth() + 1).padStart(2, "0")}-${String(expected.getDate()).padStart(2, "0")}`;
|
|
109
|
+
assert.equal(visible[i]?.key, key, label);
|
|
110
|
+
expected.setDate(expected.getDate() - 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
74
114
|
} finally {
|
|
75
115
|
if (previous === undefined) delete process.env.TZ; else process.env.TZ = previous;
|
|
76
116
|
}
|
|
77
117
|
});
|
|
118
|
+
it("starts the last column on the Sunday of the current week (058)", () => {
|
|
119
|
+
const result = buildActivityCalendar(days, "weekly", from, today);
|
|
120
|
+
const last = result.weeks[51]!;
|
|
121
|
+
assert.equal(last[0]?.key, "2026-03-08"); // Sunday of the week containing 2026-03-10
|
|
122
|
+
assert.equal(last[2]?.key, "2026-03-10"); // today, Tuesday
|
|
123
|
+
assert.ok(last.slice(3).every(cell => cell.future));
|
|
124
|
+
assert.equal(last[0]?.agents, 1); // natural-week total for 2026-03-08
|
|
125
|
+
assert.equal(last[0]?.messages, 3);
|
|
126
|
+
assert.equal(result.weeks[50]?.find(cell => cell.key === "2026-03-07")?.agents, 2);
|
|
127
|
+
});
|
|
128
|
+
it("carries history before the window into cumulative totals", () => {
|
|
129
|
+
const history = [{ date: "2020-01-01", skills: 1, mcp: 2, agents: 3, messages: 4, total: 10 }, ...days];
|
|
130
|
+
const cells = buildActivityCalendar(history, "cumulative", undefined, today).weeks.flat();
|
|
131
|
+
assert.equal(cells[0]?.total, 10);
|
|
132
|
+
assert.equal(cells[51 * 7 + 2]?.key, "2026-03-10");
|
|
133
|
+
assert.equal(cells[51 * 7 + 2]?.total, 28);
|
|
134
|
+
});
|
|
78
135
|
it("renders empty windows and bounded intensity", () => {
|
|
79
136
|
const result = buildActivityCalendar([], "daily", undefined, today);
|
|
80
137
|
assert.equal(result.weeks.length, 52);
|
|
@@ -94,3 +151,99 @@ describe("activity calendar", () => {
|
|
|
94
151
|
assert.deepEqual(computeStreaks(messageOnly, today), { current: 2, longest: 2 });
|
|
95
152
|
});
|
|
96
153
|
});
|
|
154
|
+
|
|
155
|
+
describe("agent creation buckets (051)", () => {
|
|
156
|
+
const day = (date: string, providers: Array<[string, number]>) => ({
|
|
157
|
+
date,
|
|
158
|
+
total: providers.reduce((sum, [, count]) => sum + count, 0),
|
|
159
|
+
providers: providers.map(([provider, count]) => ({ provider, label: provider, count })),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("zero-fills the window per local day and keeps per-provider slices", () => {
|
|
163
|
+
const buckets = buildAgentCreationBuckets(
|
|
164
|
+
[day("2026-03-07", [["claude", 2]]), day("2026-03-09", [["codex", 1], ["claude", 3]])],
|
|
165
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
166
|
+
);
|
|
167
|
+
assert.deepEqual(buckets.map((bucket) => bucket.key), ["2026-03-07", "2026-03-08", "2026-03-09", "2026-03-10"]);
|
|
168
|
+
assert.deepEqual(buckets.map((bucket) => bucket.count), [2, 0, 4, 0]);
|
|
169
|
+
assert.deepEqual(buckets[2]?.providers.map((slice) => [slice.provider, slice.count]), [["codex", 1], ["claude", 3]]);
|
|
170
|
+
assert.deepEqual(buckets[1]?.providers, []);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("clamps to the window, drops out-of-range days, and keeps today as the last bucket", () => {
|
|
174
|
+
const buckets = buildAgentCreationBuckets(
|
|
175
|
+
[day("2026-03-01", [["claude", 5]]), day("2026-03-10", [["claude", 1]]), day("2026-03-11", [["claude", 9]])],
|
|
176
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
177
|
+
);
|
|
178
|
+
assert.deepEqual(buckets.map((bucket) => bucket.key), ["2026-03-07", "2026-03-08", "2026-03-09", "2026-03-10"]);
|
|
179
|
+
assert.equal(buckets.reduce((sum, bucket) => sum + bucket.count, 0), 1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("ranks providers by window totals with a stable tie-break", () => {
|
|
183
|
+
const buckets = buildAgentCreationBuckets(
|
|
184
|
+
[
|
|
185
|
+
day("2026-03-08", [["codex", 1], ["claude", 1]]),
|
|
186
|
+
day("2026-03-09", [["claude", 2], ["amp", 3]]),
|
|
187
|
+
],
|
|
188
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
189
|
+
);
|
|
190
|
+
assert.deepEqual(rankCreationProviders(buckets).map((item) => [item.provider, item.count]), [
|
|
191
|
+
["amp", 3],
|
|
192
|
+
["claude", 3],
|
|
193
|
+
["codex", 1],
|
|
194
|
+
]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("stacks day segments by window rank with largest series at the bottom", () => {
|
|
198
|
+
const buckets = buildAgentCreationBuckets(
|
|
199
|
+
[
|
|
200
|
+
day("2026-03-08", [["codex", 1], ["claude", 1]]),
|
|
201
|
+
day("2026-03-09", [["claude", 2], ["amp", 3]]),
|
|
202
|
+
],
|
|
203
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
204
|
+
);
|
|
205
|
+
const ranked = rankCreationProviders(buckets);
|
|
206
|
+
// Top→bottom paint order: smallest window total present first.
|
|
207
|
+
assert.deepEqual(
|
|
208
|
+
stackCreationProviders(ranked, buckets[1]!.providers).map((s) => s.provider),
|
|
209
|
+
["codex", "claude"],
|
|
210
|
+
);
|
|
211
|
+
assert.deepEqual(
|
|
212
|
+
stackCreationProviders(ranked, buckets[2]!.providers).map((s) => s.provider),
|
|
213
|
+
["claude", "amp"],
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("activity metrics (070)", () => {
|
|
219
|
+
it("reads each metric and cycles in both directions", () => {
|
|
220
|
+
const value = { agents: 1, messages: 2, skills: 3, mcp: 4 };
|
|
221
|
+
assert.deepEqual(
|
|
222
|
+
(["sessions", "prompts", "skills", "mcp"] as const).map((metric) => metricValue(value, metric)),
|
|
223
|
+
[1, 2, 3, 4],
|
|
224
|
+
);
|
|
225
|
+
assert.equal(stepMetric("sessions", 1), "prompts");
|
|
226
|
+
assert.equal(stepMetric("mcp", 1), "sessions");
|
|
227
|
+
assert.equal(stepMetric("sessions", -1), "mcp");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("buckets daily activity by metric over the fixed window", () => {
|
|
231
|
+
const today = new Date(2026, 2, 9);
|
|
232
|
+
const buckets = buildDailyMetricBuckets(
|
|
233
|
+
[
|
|
234
|
+
{ date: "2026-03-06", skills: 9, mcp: 0, agents: 9, messages: 9, total: 27 },
|
|
235
|
+
{ date: "2026-03-08", skills: 2, mcp: 1, agents: 1, messages: 5, total: 9 },
|
|
236
|
+
],
|
|
237
|
+
"prompts",
|
|
238
|
+
{ from: new Date(2026, 2, 7).toISOString(), today },
|
|
239
|
+
);
|
|
240
|
+
assert.deepEqual(
|
|
241
|
+
buckets.map((bucket) => [bucket.key, bucket.count, bucket.providers.length]),
|
|
242
|
+
[
|
|
243
|
+
["2026-03-07", 0, 0],
|
|
244
|
+
["2026-03-08", 5, 0],
|
|
245
|
+
["2026-03-09", 0, 0],
|
|
246
|
+
],
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
});
|
package/shared/activity.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActivityDay } from "./usage.ts";
|
|
1
|
+
import type { ActivityDay, AgentCreationDay } from "./usage.ts";
|
|
2
2
|
|
|
3
3
|
function pad2(value: number): string {
|
|
4
4
|
return String(value).padStart(2, "0");
|
|
@@ -32,11 +32,33 @@ function addDays(date: Date, days: number): Date {
|
|
|
32
32
|
|
|
33
33
|
export type HeatmapMode = "daily" | "weekly" | "cumulative";
|
|
34
34
|
|
|
35
|
+
/** Chart metric switch (070); `sessions` = agent creations, `prompts` = user messages. */
|
|
36
|
+
export type ActivityMetric = "sessions" | "prompts" | "skills" | "mcp";
|
|
37
|
+
|
|
38
|
+
export const ACTIVITY_METRICS: readonly ActivityMetric[] = ["sessions", "prompts", "skills", "mcp"];
|
|
39
|
+
|
|
40
|
+
export function metricValue(
|
|
41
|
+
value: { agents: number; messages: number; skills: number; mcp: number },
|
|
42
|
+
metric: ActivityMetric,
|
|
43
|
+
): number {
|
|
44
|
+
if (metric === "sessions") return value.agents;
|
|
45
|
+
if (metric === "prompts") return value.messages;
|
|
46
|
+
return metric === "skills" ? value.skills : value.mcp;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Next / previous metric in `ACTIVITY_METRICS`, wrapping around. */
|
|
50
|
+
export function stepMetric(metric: ActivityMetric, delta: number): ActivityMetric {
|
|
51
|
+
const count = ACTIVITY_METRICS.length;
|
|
52
|
+
return ACTIVITY_METRICS[(ACTIVITY_METRICS.indexOf(metric) + delta + count * 2) % count] ?? "sessions";
|
|
53
|
+
}
|
|
54
|
+
|
|
35
55
|
export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, _from?: string, today = new Date(), locale = "en") {
|
|
36
56
|
const end = startOfLocalDay(today);
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
57
|
+
// 52 natural weeks (Sunday-start) ending with the week containing today (058):
|
|
58
|
+
// rows are weekdays (Sunday → Saturday), columns are calendar weeks. Days after
|
|
59
|
+
// today in the last column stay hidden.
|
|
60
|
+
// Range chips filter RPC data only (021). `_from` kept for call-site compatibility.
|
|
61
|
+
const start = addDays(startOfWeekSunday(end), -(51 * 7));
|
|
40
62
|
const first = start;
|
|
41
63
|
const daily = new Map(days.map(day => [day.date, day]));
|
|
42
64
|
const weekly = new Map<string, ActivityDay>();
|
|
@@ -87,7 +109,7 @@ export function buildActivityCalendar(days: readonly ActivityDay[], mode: Heatma
|
|
|
87
109
|
messages += raw?.messages ?? 0;
|
|
88
110
|
const value =
|
|
89
111
|
mode === "weekly"
|
|
90
|
-
? weekly.get(toDayKey(
|
|
112
|
+
? weekly.get(toDayKey(startOfWeekSunday(date)))
|
|
91
113
|
: mode === "cumulative"
|
|
92
114
|
? { skills, mcp, agents, messages, total: skills + mcp + agents + messages }
|
|
93
115
|
: raw;
|
|
@@ -178,3 +200,116 @@ export function computeStreaks(
|
|
|
178
200
|
|
|
179
201
|
return { current, longest };
|
|
180
202
|
}
|
|
203
|
+
|
|
204
|
+
export type CreationProviderSlice = {
|
|
205
|
+
provider: string;
|
|
206
|
+
label: string;
|
|
207
|
+
count: number;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type CreationBucket = {
|
|
211
|
+
/** Local day key; stable identity across refetches. */
|
|
212
|
+
key: string;
|
|
213
|
+
count: number;
|
|
214
|
+
/** Providers with creations that day, highest day-count first (051). Stack order uses `stackCreationProviders`. */
|
|
215
|
+
providers: CreationProviderSlice[];
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
219
|
+
|
|
220
|
+
/** DST-proof day index for a local calendar date. */
|
|
221
|
+
function dayIndex(date: Date): number {
|
|
222
|
+
return Math.floor(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / DAY_MS);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Zero-filled daily buckets over `[from, today]` (051). Days without creations
|
|
227
|
+
* stay as empty buckets so the histogram never skips a date.
|
|
228
|
+
*/
|
|
229
|
+
export function buildAgentCreationBuckets(
|
|
230
|
+
days: readonly AgentCreationDay[],
|
|
231
|
+
options: { from: string; today?: Date },
|
|
232
|
+
): CreationBucket[] {
|
|
233
|
+
const today = startOfLocalDay(options.today ?? new Date());
|
|
234
|
+
const todayKey = toDayKey(today);
|
|
235
|
+
const fromDate = new Date(options.from);
|
|
236
|
+
const start = startOfLocalDay(Number.isNaN(fromDate.getTime()) ? today : fromDate);
|
|
237
|
+
const startKey = toDayKey(start);
|
|
238
|
+
const byDay = new Map<string, CreationProviderSlice[]>();
|
|
239
|
+
for (const day of days) {
|
|
240
|
+
if (day.date < startKey || day.date > todayKey) continue;
|
|
241
|
+
byDay.set(
|
|
242
|
+
day.date,
|
|
243
|
+
day.providers.filter((item) => item.count > 0),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const buckets: CreationBucket[] = [];
|
|
247
|
+
for (let cursor = start; dayIndex(cursor) <= dayIndex(today); cursor = addDays(cursor, 1)) {
|
|
248
|
+
const key = toDayKey(cursor);
|
|
249
|
+
const providers = byDay.get(key) ?? [];
|
|
250
|
+
buckets.push({
|
|
251
|
+
key,
|
|
252
|
+
count: providers.reduce((sum, item) => sum + item.count, 0),
|
|
253
|
+
providers,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return buckets;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* One bucket per local day over the same window as `buildAgentCreationBuckets`,
|
|
261
|
+
* valued by `metric` from `usage.activity-by-day` (070). No provider slices:
|
|
262
|
+
* only session creations carry a per-provider breakdown.
|
|
263
|
+
*/
|
|
264
|
+
export function buildDailyMetricBuckets(
|
|
265
|
+
days: readonly ActivityDay[],
|
|
266
|
+
metric: ActivityMetric,
|
|
267
|
+
options: { from: string; today?: Date },
|
|
268
|
+
): CreationBucket[] {
|
|
269
|
+
const byDay = new Map(days.map((day) => [day.date, metricValue(day, metric)]));
|
|
270
|
+
return buildAgentCreationBuckets([], options).map((bucket) => ({
|
|
271
|
+
...bucket,
|
|
272
|
+
count: byDay.get(bucket.key) ?? 0,
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Providers across the whole window, ranked by total creations (051). Drives
|
|
278
|
+
* the stable stack order and colour assignment; tooltip rows use
|
|
279
|
+
* `stackCreationProviders` so zero-count series are omitted (056).
|
|
280
|
+
*/
|
|
281
|
+
export function rankCreationProviders(
|
|
282
|
+
buckets: readonly CreationBucket[],
|
|
283
|
+
): CreationProviderSlice[] {
|
|
284
|
+
const totals = new Map<string, CreationProviderSlice>();
|
|
285
|
+
for (const bucket of buckets) {
|
|
286
|
+
for (const slice of bucket.providers) {
|
|
287
|
+
const current = totals.get(slice.provider);
|
|
288
|
+
if (current) current.count += slice.count;
|
|
289
|
+
else totals.set(slice.provider, { ...slice });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return [...totals.values()].sort(
|
|
293
|
+
(a, b) => b.count - a.count || a.provider.localeCompare(b.provider),
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Day segments in top→bottom paint order for a column stack (051): follows
|
|
299
|
+
* window rank so every bar shares the same series order; largest window total
|
|
300
|
+
* sits at the bottom. Providers with no creations that day are omitted.
|
|
301
|
+
*/
|
|
302
|
+
export function stackCreationProviders(
|
|
303
|
+
ranked: readonly CreationProviderSlice[],
|
|
304
|
+
dayProviders: readonly CreationProviderSlice[],
|
|
305
|
+
): CreationProviderSlice[] {
|
|
306
|
+
const byId = new Map(dayProviders.map((slice) => [slice.provider, slice]));
|
|
307
|
+
// `ranked` is window-total descending; reverse so the first child (top of a
|
|
308
|
+
// column + flex-end stack) is the smallest series present that day.
|
|
309
|
+
return [...ranked]
|
|
310
|
+
.reverse()
|
|
311
|
+
.flatMap((item) => {
|
|
312
|
+
const slice = byId.get(item.provider);
|
|
313
|
+
return slice && slice.count > 0 ? [slice] : [];
|
|
314
|
+
});
|
|
315
|
+
}
|
package/shared/classify.test.ts
CHANGED
|
@@ -12,6 +12,7 @@ describe("normalizeProvider", () => {
|
|
|
12
12
|
assert.equal(normalizeProvider("opencode"), "opencode");
|
|
13
13
|
assert.equal(normalizeProvider("codex"), "codex");
|
|
14
14
|
assert.equal(normalizeProvider("pi"), "pi");
|
|
15
|
+
assert.equal(normalizeProvider("omp"), "omp");
|
|
15
16
|
assert.equal(normalizeProvider("cursor"), "cursor");
|
|
16
17
|
assert.equal(normalizeProvider("codebuddy-code"), "codebuddy");
|
|
17
18
|
});
|
package/shared/classify.ts
CHANGED
|
@@ -118,12 +118,15 @@ export function normalizeProvider(provider: string): string {
|
|
|
118
118
|
if (head === "claude" || head.startsWith("claude")) return "claude";
|
|
119
119
|
if (head === "opencode") return "opencode";
|
|
120
120
|
if (head === "codex") return "codex";
|
|
121
|
-
if (head === "pi"
|
|
121
|
+
if (head === "pi") return "pi";
|
|
122
|
+
// Oh My Pi is its own Paseo provider (manifest id `omp`), not a Pi alias (071).
|
|
123
|
+
if (head === "omp") return "omp";
|
|
122
124
|
if (head === "cursor") return "cursor";
|
|
123
125
|
if (head === "codebuddy" || head === "codebuddy-code") return "codebuddy";
|
|
124
126
|
return head;
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
|
|
127
130
|
function expandHome(path: string, homeDir?: string): string {
|
|
128
131
|
if (homeDir && path.startsWith("~/")) {
|
|
129
132
|
return `${homeDir.replace(/\/+$/, "")}/${path.slice(2)}`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
explorerAgentDisplaySettings,
|
|
5
|
+
migrateExplorerAgentDisplay,
|
|
6
|
+
} from "./explorer-agent-display.ts";
|
|
7
|
+
|
|
8
|
+
test("Explorer display settings default Skills and MCP to timeline", () => {
|
|
9
|
+
const values = explorerAgentDisplaySettings.schema.parse({});
|
|
10
|
+
assert.equal(values.rankView, "timeline");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("Explorer display settings migrate v1 while preserving Agent filters", () => {
|
|
14
|
+
const migrated = migrateExplorerAgentDisplay(
|
|
15
|
+
{
|
|
16
|
+
sort: "name",
|
|
17
|
+
group: "provider",
|
|
18
|
+
show: ["messages"],
|
|
19
|
+
status: ["active", "archived"],
|
|
20
|
+
lifecycle: ["running"],
|
|
21
|
+
},
|
|
22
|
+
1,
|
|
23
|
+
);
|
|
24
|
+
const values = explorerAgentDisplaySettings.schema.parse(migrated);
|
|
25
|
+
assert.equal(values.rankView, "timeline");
|
|
26
|
+
assert.equal(values.sort, "name");
|
|
27
|
+
assert.deepEqual(values.status, ["active", "archived"]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("Explorer display settings preserve the v2 Skills view as the shared rank view", () => {
|
|
31
|
+
const migrated = migrateExplorerAgentDisplay(
|
|
32
|
+
{
|
|
33
|
+
sort: "updated",
|
|
34
|
+
group: "none",
|
|
35
|
+
show: [],
|
|
36
|
+
status: ["active"],
|
|
37
|
+
lifecycle: ["idle", "running", "error", "closed"],
|
|
38
|
+
skillView: "timeline",
|
|
39
|
+
},
|
|
40
|
+
2,
|
|
41
|
+
);
|
|
42
|
+
const values = explorerAgentDisplaySettings.schema.parse(migrated);
|
|
43
|
+
assert.equal(values.rankView, "timeline");
|
|
44
|
+
assert.equal("skillView" in values, false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("Explorer display settings preserve an explicit v2 ranked Skills view", () => {
|
|
48
|
+
const migrated = migrateExplorerAgentDisplay(
|
|
49
|
+
{
|
|
50
|
+
sort: "updated",
|
|
51
|
+
group: "none",
|
|
52
|
+
show: [],
|
|
53
|
+
status: ["active"],
|
|
54
|
+
lifecycle: ["idle", "running", "error", "closed"],
|
|
55
|
+
skillView: "ranked",
|
|
56
|
+
},
|
|
57
|
+
2,
|
|
58
|
+
);
|
|
59
|
+
const values = explorerAgentDisplaySettings.schema.parse(migrated);
|
|
60
|
+
assert.equal(values.rankView, "ranked");
|
|
61
|
+
});
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { defineSettings } from "@getpaseo/plugin";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export function migrateExplorerAgentDisplay(values: unknown, fromVersion: number): unknown {
|
|
5
|
+
if (
|
|
6
|
+
fromVersion < 3 &&
|
|
7
|
+
values !== null &&
|
|
8
|
+
typeof values === "object" &&
|
|
9
|
+
!Array.isArray(values)
|
|
10
|
+
) {
|
|
11
|
+
const { skillView, ...rest } = values as Record<string, unknown>;
|
|
12
|
+
return {
|
|
13
|
+
...rest,
|
|
14
|
+
rankView: skillView === "ranked" ? "ranked" : "timeline",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return values;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Host-scoped Explorer display prefs (Agents menu + shared Skills/MCP view). */
|
|
5
21
|
export const explorerAgentDisplaySettings = defineSettings({
|
|
6
22
|
id: "explorer-agent-display",
|
|
7
23
|
scope: "host",
|
|
8
|
-
version:
|
|
24
|
+
version: 3,
|
|
9
25
|
schema: z.object({
|
|
10
26
|
sort: z.enum(["created", "updated", "name", "messages", "status"]).default("updated"),
|
|
11
27
|
group: z.enum(["none", "provider", "status"]).default("none"),
|
|
@@ -14,7 +30,9 @@ export const explorerAgentDisplaySettings = defineSettings({
|
|
|
14
30
|
lifecycle: z
|
|
15
31
|
.array(z.enum(["idle", "running", "error", "closed"]))
|
|
16
32
|
.default(["idle", "running", "error", "closed"]),
|
|
33
|
+
rankView: z.enum(["ranked", "timeline"]).default("timeline"),
|
|
17
34
|
}),
|
|
35
|
+
migrate: migrateExplorerAgentDisplay,
|
|
18
36
|
});
|
|
19
37
|
|
|
20
38
|
export type ExplorerAgentDisplayValues = z.infer<
|
|
@@ -27,4 +45,5 @@ export const EXPLORER_AGENT_DISPLAY_DEFAULTS: ExplorerAgentDisplayValues = {
|
|
|
27
45
|
show: [],
|
|
28
46
|
status: ["active"],
|
|
29
47
|
lifecycle: ["idle", "running", "error", "closed"],
|
|
48
|
+
rankView: "timeline",
|
|
30
49
|
};
|
package/shared/format.test.ts
CHANGED
|
@@ -2,9 +2,10 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
3
|
import {
|
|
4
4
|
formatActivityTime,
|
|
5
|
+
formatCount,
|
|
5
6
|
formatDisplayName,
|
|
7
|
+
formatDuration,
|
|
6
8
|
formatLocalDateTime,
|
|
7
|
-
formatUpdatedAt,
|
|
8
9
|
} from "./format.ts";
|
|
9
10
|
|
|
10
11
|
const NOW = new Date(2026, 8, 18, 15, 30);
|
|
@@ -39,9 +40,33 @@ describe("formatActivityTime", () => {
|
|
|
39
40
|
assert.equal(formatActivityTime(undefined, "en", NOW), "—");
|
|
40
41
|
assert.equal(formatActivityTime("not-a-date", "en", NOW), "not-a-date");
|
|
41
42
|
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("formatDuration", () => {
|
|
46
|
+
it("steps through minutes, hours, days and months", () => {
|
|
47
|
+
assert.equal(formatDuration(0), "<1 min");
|
|
48
|
+
assert.equal(formatDuration(59_000), "<1 min");
|
|
49
|
+
assert.equal(formatDuration(59 * 60_000), "59 min");
|
|
50
|
+
assert.equal(formatDuration(3.25 * 3_600_000), "3.3 h");
|
|
51
|
+
assert.equal(formatDuration(47 * 3_600_000), "47 h");
|
|
52
|
+
assert.equal(formatDuration(48 * 3_600_000), "2 days");
|
|
53
|
+
assert.equal(formatDuration(277.7 * 3_600_000), "11.6 days");
|
|
54
|
+
assert.equal(formatDuration(100 * 24 * 3_600_000), "3.3 months");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("rejects negative and non-finite input", () => {
|
|
58
|
+
assert.equal(formatDuration(-1), "—");
|
|
59
|
+
assert.equal(formatDuration(Number.NaN), "—");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
42
62
|
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
describe("formatCount", () => {
|
|
64
|
+
it("keeps small counts exact and abbreviates k / M", () => {
|
|
65
|
+
assert.equal(formatCount(0), "0");
|
|
66
|
+
assert.equal(formatCount(9999), "9999");
|
|
67
|
+
assert.equal(formatCount(12345), "12.3k");
|
|
68
|
+
assert.equal(formatCount(10000), "10k");
|
|
69
|
+
assert.equal(formatCount(1234567), "1.2M");
|
|
45
70
|
});
|
|
46
71
|
});
|
|
47
72
|
|
package/shared/format.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { messagesFor } from "./i18n.ts";
|
|
2
|
+
|
|
1
3
|
/** Format stored ISO timestamps for UI / export in the local timezone + locale. */
|
|
2
4
|
export function formatLocalDateTime(
|
|
3
5
|
iso: string | null | undefined,
|
|
@@ -50,5 +52,26 @@ export function formatActivityTime(
|
|
|
50
52
|
return date.toLocaleString(locale, options);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const MINUTE_MS = 60_000;
|
|
56
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
57
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
58
|
+
|
|
59
|
+
/** Compact count for KPI tiles: 9999 → `9999`, 12345 → `12.3k`, 1234567 → `1.2M`. */
|
|
60
|
+
export function formatCount(value: number): string {
|
|
61
|
+
if (value >= 1_000_000) return `${Number((value / 1_000_000).toFixed(1))}M`;
|
|
62
|
+
if (value >= 10_000) return `${Number((value / 1_000).toFixed(1))}k`;
|
|
63
|
+
return String(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Compact duration for agent lifetimes (049); units follow the app language (066). */
|
|
67
|
+
export function formatDuration(ms: number, locale = "en"): string {
|
|
68
|
+
if (!Number.isFinite(ms) || ms < 0) return "—";
|
|
69
|
+
const m = messagesFor(locale).duration;
|
|
70
|
+
if (ms < MINUTE_MS) return m.underMinute;
|
|
71
|
+
if (ms < HOUR_MS) return m.minutes(Math.floor(ms / MINUTE_MS));
|
|
72
|
+
const hours = ms / HOUR_MS;
|
|
73
|
+
if (hours < 48) return m.hours(Number(hours.toFixed(1)));
|
|
74
|
+
const days = ms / DAY_MS;
|
|
75
|
+
if (days < 60) return m.days(Number(days.toFixed(1)));
|
|
76
|
+
return m.months(Number((days / 30.44).toFixed(1)));
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { formatDuration } from "./format.ts";
|
|
4
|
+
import { messagesFor, resolveAppLanguage } from "./i18n.ts";
|
|
5
|
+
|
|
6
|
+
test("resolveAppLanguage honors an explicit Paseo setting", () => {
|
|
7
|
+
assert.equal(resolveAppLanguage("zh-CN", ["en-US"]), "zh-CN");
|
|
8
|
+
assert.equal(resolveAppLanguage("ja", ["zh-CN"]), "ja");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("resolveAppLanguage maps system to the OS preference", () => {
|
|
12
|
+
assert.equal(resolveAppLanguage("system", ["zh-TW", "en"]), "zh-CN");
|
|
13
|
+
assert.equal(resolveAppLanguage("system", ["pt-PT"]), "pt-BR");
|
|
14
|
+
assert.equal(resolveAppLanguage("system", ["de-DE", "ko-KR"]), "ko");
|
|
15
|
+
assert.equal(resolveAppLanguage("system", ["de-DE"]), "en");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("resolveAppLanguage treats missing or unknown settings like system", () => {
|
|
19
|
+
assert.equal(resolveAppLanguage(undefined, []), "en");
|
|
20
|
+
assert.equal(resolveAppLanguage("klingon", ["zh-CN"]), "zh-CN");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("messagesFor returns zh-CN copy and falls back to English", () => {
|
|
24
|
+
assert.equal(messagesFor("zh-CN").common.retry, "重试");
|
|
25
|
+
assert.equal(messagesFor("zh-CN").common.lastUsed("3 分钟前"), "最近 3 分钟前");
|
|
26
|
+
assert.equal(messagesFor("fr").common.retry, messagesFor("en").common.retry);
|
|
27
|
+
assert.equal(messagesFor("en").workspace.state.subagents(1), "1 subagent");
|
|
28
|
+
assert.equal(messagesFor("en").workspace.state.subagents(2), "2 subagents");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("formatDuration uses the locale's units", () => {
|
|
32
|
+
assert.equal(formatDuration(5 * 60_000, "en"), "5 min");
|
|
33
|
+
assert.equal(formatDuration(5 * 60_000, "zh-CN"), "5 分钟");
|
|
34
|
+
});
|