@koinzhang/paseo-plugin-activity 0.1.0 → 0.2.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 +56 -0
- package/README.md +71 -0
- package/client/activity-heatmap.tsx +72 -14
- package/client/global-surface.tsx +24 -25
- package/client/panel.tsx +1 -0
- package/client/range.ts +20 -0
- package/client/usage-stats.tsx +7 -5
- package/client/workspace/agent-row.tsx +117 -0
- package/client/workspace/agents-section.tsx +323 -0
- package/client/workspace/constants.ts +121 -0
- package/client/workspace/display-menu.tsx +116 -0
- package/client/workspace/filters.ts +30 -0
- package/client/workspace/list-host-agents.ts +57 -0
- package/client/workspace/panel.tsx +800 -0
- package/client/workspace/rank-section.tsx +121 -0
- package/client/workspace-panel.tsx +2 -0
- package/index.client.tsx +20 -13
- package/index.server.ts +11 -0
- package/package.json +8 -2
- package/server/agents.test.ts +20 -1
- package/server/agents.ts +2 -1
- package/server/background-sync.test.ts +14 -3
- package/server/background-sync.ts +16 -5
- package/server/handlers-query.test.ts +58 -0
- package/server/handlers.ts +73 -2
- package/server/messages.test.ts +8 -2
- package/server/store.test.ts +13 -0
- package/server/store.ts +2 -2
- package/shared/activity.test.ts +22 -12
- package/shared/activity.ts +8 -13
- package/shared/agent-page-size.test.ts +11 -0
- package/shared/agent-title-search.test.ts +28 -0
- package/shared/agent-title-search.ts +12 -0
- package/shared/explorer-agent-display.ts +30 -0
- package/shared/format.test.ts +22 -1
- package/shared/format.ts +24 -0
- package/shared/insights.test.ts +38 -18
- package/shared/insights.ts +38 -19
- package/shared/list-agent-pages.test.ts +51 -0
- package/shared/list-agent-pages.ts +31 -0
- package/shared/usage.test.ts +248 -0
- package/shared/usage.ts +327 -11
package/shared/activity.test.ts
CHANGED
|
@@ -13,9 +13,9 @@ describe("activity calendar", () => {
|
|
|
13
13
|
it("formats months with the explicit app language", () => {
|
|
14
14
|
const english = buildActivityCalendar([], "daily", from, today, "en");
|
|
15
15
|
const chinese = buildActivityCalendar([], "daily", from, today, "zh-CN");
|
|
16
|
-
assert.equal(english.months.length,
|
|
17
|
-
assert.equal(english.months[
|
|
18
|
-
assert.equal(chinese.months[
|
|
16
|
+
assert.equal(english.months.length, 12);
|
|
17
|
+
assert.equal(english.months[11]?.label, "Mar");
|
|
18
|
+
assert.equal(chinese.months[11]?.label, "3月");
|
|
19
19
|
});
|
|
20
20
|
it("uses 12 evenly spaced month labels for a year window", () => {
|
|
21
21
|
const result = buildActivityCalendar([], "daily", undefined, new Date(2026, 8, 19), "en");
|
|
@@ -37,6 +37,14 @@ describe("activity calendar", () => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
+
it("keeps 52-week layout even when a short range from is passed (021)", () => {
|
|
41
|
+
const short = buildActivityCalendar([], "daily", from, today, "en");
|
|
42
|
+
const all = buildActivityCalendar([], "daily", undefined, today, "en");
|
|
43
|
+
assert.equal(short.weeks.length, 52);
|
|
44
|
+
assert.equal(short.months.length, 12);
|
|
45
|
+
assert.equal(short.weeks.length, all.weeks.length);
|
|
46
|
+
assert.equal(short.months.length, all.months.length);
|
|
47
|
+
});
|
|
40
48
|
it("carries cumulative counts across missing days including today", () => {
|
|
41
49
|
const cells = buildActivityCalendar(days, "cumulative", from, today).weeks.flat();
|
|
42
50
|
assert.equal(cells.find(c => c.key === "2026-03-08")?.total, 9);
|
|
@@ -47,23 +55,25 @@ describe("activity calendar", () => {
|
|
|
47
55
|
});
|
|
48
56
|
it("keeps daily gaps empty and aggregates Sunday-start weeks", () => {
|
|
49
57
|
assert.equal(buildActivityCalendar(days, "daily", from, today).weeks.flat().find(c => c.key === "2026-03-08")?.total, 0);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
const weekStart = "2026-03-08"; // Sunday containing 2026-03-09
|
|
59
|
+
const weeklyCell = buildActivityCalendar(days, "weekly", from, today)
|
|
60
|
+
.weeks.flat()
|
|
61
|
+
.find((c) => c.key === weekStart);
|
|
62
|
+
assert.equal(weeklyCell?.total, 9);
|
|
63
|
+
assert.equal(weeklyCell?.agents, 1);
|
|
64
|
+
assert.equal(weeklyCell?.messages, 3);
|
|
54
65
|
});
|
|
55
|
-
it("includes the current week across DST and marks padding cells", () => {
|
|
66
|
+
it("includes the current week across DST and marks future padding cells", () => {
|
|
56
67
|
const previous = process.env.TZ;
|
|
57
68
|
process.env.TZ = "America/New_York";
|
|
58
69
|
try {
|
|
59
70
|
const result = buildActivityCalendar([], "daily", new Date(2026, 2, 1).toISOString(), new Date(2026, 2, 15));
|
|
60
|
-
assert.equal(result.weeks.length,
|
|
61
|
-
assert.equal(result.weeks[
|
|
62
|
-
assert.equal(result.weeks[
|
|
71
|
+
assert.equal(result.weeks.length, 52);
|
|
72
|
+
assert.equal(result.weeks[51]?.[0]?.key, "2026-03-15");
|
|
73
|
+
assert.equal(result.weeks[51]?.[1]?.future, true);
|
|
63
74
|
} finally {
|
|
64
75
|
if (previous === undefined) delete process.env.TZ; else process.env.TZ = previous;
|
|
65
76
|
}
|
|
66
|
-
assert.equal(buildActivityCalendar([], "daily", from, today).weeks[0]?.[0]?.excluded, true);
|
|
67
77
|
});
|
|
68
78
|
it("renders empty windows and bounded intensity", () => {
|
|
69
79
|
const result = buildActivityCalendar([], "daily", undefined, today);
|
package/shared/activity.ts
CHANGED
|
@@ -32,19 +32,12 @@ function addDays(date: Date, days: number): Date {
|
|
|
32
32
|
|
|
33
33
|
export type HeatmapMode = "daily" | "weekly" | "cumulative";
|
|
34
34
|
|
|
35
|
-
export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode,
|
|
35
|
+
export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, _from?: string, today = new Date(), locale = "en") {
|
|
36
36
|
const end = startOfLocalDay(today);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
first = Number.isNaN(parsed.getTime()) ? addDays(end, -363) : parsed;
|
|
42
|
-
start = startOfWeekSunday(first);
|
|
43
|
-
} else {
|
|
44
|
-
// Fixed 52-week year window (ChatGPT-style): current week + 51 prior weeks.
|
|
45
|
-
start = addDays(startOfWeekSunday(end), -7 * 51);
|
|
46
|
-
first = start;
|
|
47
|
-
}
|
|
37
|
+
// Always fixed 52-week year window (ChatGPT-style). Range chips filter RPC data only —
|
|
38
|
+
// short windows must not shrink the grid (021). `_from` kept for call-site compatibility.
|
|
39
|
+
const start = addDays(startOfWeekSunday(end), -7 * 51);
|
|
40
|
+
const first = start;
|
|
48
41
|
const daily = new Map(days.map(day => [day.date, day]));
|
|
49
42
|
const weekly = new Map<string, ActivityDay>();
|
|
50
43
|
for (const day of days) {
|
|
@@ -126,7 +119,7 @@ export function buildActivityCalendar(days: readonly ActivityDay[], mode: Heatma
|
|
|
126
119
|
(endMonth.getMonth() - startMonth.getMonth()) +
|
|
127
120
|
1;
|
|
128
121
|
const monthCount = Math.min(12, Math.max(1, spanMonths));
|
|
129
|
-
const months: Array<{ index: number; label: string }> = [];
|
|
122
|
+
const months: Array<{ index: number; label: string; year: number; month: number }> = [];
|
|
130
123
|
for (let i = 0; i < monthCount; i++) {
|
|
131
124
|
const date =
|
|
132
125
|
monthCount === 12
|
|
@@ -135,6 +128,8 @@ export function buildActivityCalendar(days: readonly ActivityDay[], mode: Heatma
|
|
|
135
128
|
months.push({
|
|
136
129
|
index: (i / monthCount) * weeks.length,
|
|
137
130
|
label: date.toLocaleDateString(locale, { month: "short" }),
|
|
131
|
+
year: date.getFullYear(),
|
|
132
|
+
month: date.getMonth(),
|
|
138
133
|
});
|
|
139
134
|
}
|
|
140
135
|
return { weeks, months, max };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { AGENT_PAGE_SIZE } from "../client/workspace/constants.ts";
|
|
4
|
+
|
|
5
|
+
test("AGENT_PAGE_SIZE yields single page for ≤ page size", () => {
|
|
6
|
+
assert.ok(AGENT_PAGE_SIZE > 0);
|
|
7
|
+
const pageCount = (n: number) => Math.max(1, Math.ceil(n / AGENT_PAGE_SIZE));
|
|
8
|
+
assert.equal(pageCount(0), 1);
|
|
9
|
+
assert.equal(pageCount(AGENT_PAGE_SIZE), 1);
|
|
10
|
+
assert.equal(pageCount(AGENT_PAGE_SIZE + 1), 2);
|
|
11
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { matchesAgentTitleSearch } from "./agent-title-search.ts";
|
|
4
|
+
|
|
5
|
+
describe("matchesAgentTitleSearch", () => {
|
|
6
|
+
it("matches when every token appears (order-independent)", () => {
|
|
7
|
+
assert.equal(matchesAgentTitleSearch("Fix the login bug", "fix bug"), true);
|
|
8
|
+
assert.equal(matchesAgentTitleSearch("Fix the login bug", "bug fix"), true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("is case-insensitive and ignores extra whitespace", () => {
|
|
12
|
+
assert.equal(matchesAgentTitleSearch("Agent Activity", " agent act "), true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("rejects when any token is missing", () => {
|
|
16
|
+
assert.equal(matchesAgentTitleSearch("Fix the login bug", "fix crash"), false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("treats blank query as match-all", () => {
|
|
20
|
+
assert.equal(matchesAgentTitleSearch("Anything", ""), true);
|
|
21
|
+
assert.equal(matchesAgentTitleSearch("Anything", " "), true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("still supports a single contiguous substring token", () => {
|
|
25
|
+
assert.equal(matchesAgentTitleSearch("workspace-activity", "activity"), true);
|
|
26
|
+
assert.equal(matchesAgentTitleSearch("workspace-activity", "work act"), true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Tokenized title match: every whitespace-separated token must appear in the haystack. */
|
|
2
|
+
|
|
3
|
+
export function matchesAgentTitleSearch(title: string, query: string): boolean {
|
|
4
|
+
const haystack = title.toLowerCase();
|
|
5
|
+
const tokens = query
|
|
6
|
+
.trim()
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.split(/\s+/)
|
|
9
|
+
.filter((token) => token.length > 0);
|
|
10
|
+
if (tokens.length === 0) return true;
|
|
11
|
+
return tokens.every((token) => haystack.includes(token));
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineSettings } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/** Host-scoped Explorer Agents menu prefs (Sort / Group / Show / Status / Lifecycle). */
|
|
5
|
+
export const explorerAgentDisplaySettings = defineSettings({
|
|
6
|
+
id: "explorer-agent-display",
|
|
7
|
+
scope: "host",
|
|
8
|
+
version: 1,
|
|
9
|
+
schema: z.object({
|
|
10
|
+
sort: z.enum(["created", "updated", "name", "messages", "status"]).default("updated"),
|
|
11
|
+
group: z.enum(["none", "provider", "status"]).default("none"),
|
|
12
|
+
show: z.array(z.enum(["provider", "calls", "messages", "updated"])).default([]),
|
|
13
|
+
status: z.array(z.enum(["active", "archived"])).default(["active"]),
|
|
14
|
+
lifecycle: z
|
|
15
|
+
.array(z.enum(["idle", "running", "error", "closed"]))
|
|
16
|
+
.default(["idle", "running", "error", "closed"]),
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type ExplorerAgentDisplayValues = z.infer<
|
|
21
|
+
typeof explorerAgentDisplaySettings.schema
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
export const EXPLORER_AGENT_DISPLAY_DEFAULTS: ExplorerAgentDisplayValues = {
|
|
25
|
+
sort: "updated",
|
|
26
|
+
group: "none",
|
|
27
|
+
show: [],
|
|
28
|
+
status: ["active"],
|
|
29
|
+
lifecycle: ["idle", "running", "error", "closed"],
|
|
30
|
+
};
|
package/shared/format.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import { formatDayTime, formatDisplayName } from "./format.ts";
|
|
3
|
+
import { formatDayTime, formatDisplayName, formatUpdatedAt } from "./format.ts";
|
|
4
4
|
|
|
5
5
|
const NOW = new Date(2026, 8, 18, 15, 30);
|
|
6
6
|
|
|
@@ -29,6 +29,27 @@ describe("formatDayTime", () => {
|
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
describe("formatUpdatedAt", () => {
|
|
33
|
+
it("uses locale month/day + time for the same year", () => {
|
|
34
|
+
const text = formatUpdatedAt(new Date(2026, 8, 17, 14, 2).toISOString(), "en", NOW);
|
|
35
|
+
assert.match(text, /Sep/);
|
|
36
|
+
assert.match(text, /17/);
|
|
37
|
+
assert.doesNotMatch(text, /2026/);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("includes the year when the date is not this year", () => {
|
|
41
|
+
const text = formatUpdatedAt(new Date(2025, 11, 31, 23, 59).toISOString(), "en", NOW);
|
|
42
|
+
assert.match(text, /2025/);
|
|
43
|
+
assert.match(text, /Dec/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns the placeholder for empty and keeps invalid input", () => {
|
|
47
|
+
assert.equal(formatUpdatedAt(null, "en", NOW), "—");
|
|
48
|
+
assert.equal(formatUpdatedAt(undefined, "en", NOW), "—");
|
|
49
|
+
assert.equal(formatUpdatedAt("not-a-date", "en", NOW), "not-a-date");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
32
53
|
describe("formatDisplayName", () => {
|
|
33
54
|
it("replaces - and _ with spaces and title-cases every word", () => {
|
|
34
55
|
assert.equal(formatDisplayName("git-commit-push"), "Git Commit Push");
|
package/shared/format.ts
CHANGED
|
@@ -43,3 +43,27 @@ export function formatDayTime(
|
|
|
43
43
|
if (date.getFullYear() === now.getFullYear()) return `${monthDay} ${time}`;
|
|
44
44
|
return `${date.getFullYear()}-${monthDay} ${time}`;
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Agent list "Updated" stamp: app locale + local timezone.
|
|
49
|
+
* Same calendar year → month/day + time; otherwise also includes the year.
|
|
50
|
+
*/
|
|
51
|
+
export function formatUpdatedAt(
|
|
52
|
+
iso: string | null | undefined,
|
|
53
|
+
locale = "en",
|
|
54
|
+
now: Date = new Date(),
|
|
55
|
+
): string {
|
|
56
|
+
if (!iso) return "—";
|
|
57
|
+
const date = new Date(iso);
|
|
58
|
+
if (Number.isNaN(date.getTime())) return iso;
|
|
59
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
60
|
+
month: "short",
|
|
61
|
+
day: "numeric",
|
|
62
|
+
hour: "numeric",
|
|
63
|
+
minute: "2-digit",
|
|
64
|
+
};
|
|
65
|
+
if (date.getFullYear() !== now.getFullYear()) {
|
|
66
|
+
options.year = "numeric";
|
|
67
|
+
}
|
|
68
|
+
return date.toLocaleString(locale, options);
|
|
69
|
+
}
|
package/shared/insights.test.ts
CHANGED
|
@@ -17,6 +17,8 @@ function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem,
|
|
|
17
17
|
shellTop: [],
|
|
18
18
|
models: [],
|
|
19
19
|
agentCount: 0,
|
|
20
|
+
codingAgentCount: 0,
|
|
21
|
+
chatAgentCount: 0,
|
|
20
22
|
workspaceCount: 0,
|
|
21
23
|
messageCount: 0,
|
|
22
24
|
callCount: 0,
|
|
@@ -25,7 +27,7 @@ function provider(partial: Partial<ProviderUsageItem> & Pick<ProviderUsageItem,
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
describe("buildActivityInsights", () => {
|
|
28
|
-
it("returns habit
|
|
30
|
+
it("returns habit → preference → structure 8 rows", () => {
|
|
29
31
|
// 2026-03-07 Sat, 2026-03-09 Mon — Mon has more messages → Peak weekday Mon
|
|
30
32
|
const days = [
|
|
31
33
|
{ date: "2026-03-07", skills: 2, mcp: 0, agents: 1, messages: 4, total: 2 },
|
|
@@ -36,11 +38,10 @@ describe("buildActivityInsights", () => {
|
|
|
36
38
|
summary: {
|
|
37
39
|
skills: 2,
|
|
38
40
|
mcp: 3,
|
|
39
|
-
agents:
|
|
41
|
+
agents: 5,
|
|
40
42
|
messages: 14,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
fileWrites: 2,
|
|
43
|
+
codingAgents: 3,
|
|
44
|
+
chatAgents: 1,
|
|
44
45
|
longestStreak: 6,
|
|
45
46
|
},
|
|
46
47
|
providers: [
|
|
@@ -48,12 +49,18 @@ describe("buildActivityInsights", () => {
|
|
|
48
49
|
provider: "codex",
|
|
49
50
|
label: "Codex",
|
|
50
51
|
messageCount: 10,
|
|
52
|
+
agentCount: 3,
|
|
53
|
+
codingAgentCount: 2,
|
|
54
|
+
chatAgentCount: 1,
|
|
51
55
|
models: [{ model: "gpt-5.4", count: 10 }],
|
|
52
56
|
}),
|
|
53
57
|
provider({
|
|
54
58
|
provider: "claude",
|
|
55
59
|
label: "Claude",
|
|
56
60
|
messageCount: 4,
|
|
61
|
+
agentCount: 2,
|
|
62
|
+
codingAgentCount: 1,
|
|
63
|
+
chatAgentCount: 0,
|
|
57
64
|
models: [{ model: "opus", count: 4 }],
|
|
58
65
|
}),
|
|
59
66
|
],
|
|
@@ -68,54 +75,67 @@ describe("buildActivityInsights", () => {
|
|
|
68
75
|
"Active days",
|
|
69
76
|
"Longest streak",
|
|
70
77
|
"Busiest day",
|
|
78
|
+
"Peak weekday",
|
|
79
|
+
"Top provider",
|
|
71
80
|
"Top model",
|
|
72
81
|
"Messages per agent",
|
|
73
|
-
"Tools per message",
|
|
74
82
|
"Coding vs chat",
|
|
75
|
-
"Peak weekday",
|
|
76
83
|
],
|
|
77
84
|
);
|
|
78
85
|
assert.equal(rows[0]?.value, "2");
|
|
79
86
|
assert.equal(rows[1]?.value, "6 days");
|
|
80
87
|
assert.equal(rows[2]?.value, "Mar 9 · 10 messages");
|
|
81
|
-
assert.equal(rows[3]?.value, "
|
|
82
|
-
assert.equal(rows[4]?.value, "
|
|
83
|
-
assert.equal(rows[5]?.value, "
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
assert.equal(rows[7]?.value, "
|
|
88
|
+
assert.equal(rows[3]?.value, "Mon");
|
|
89
|
+
assert.equal(rows[4]?.value, "Codex · 71%");
|
|
90
|
+
assert.equal(rows[5]?.value, "Gpt 5.4 · 71%");
|
|
91
|
+
assert.equal(rows[6]?.value, "2.8");
|
|
92
|
+
// 3 coding / (3+1) active → 75%
|
|
93
|
+
assert.equal(rows[7]?.value, "75% coding");
|
|
87
94
|
});
|
|
88
95
|
|
|
89
|
-
it("
|
|
96
|
+
it("hides Top provider when filtered; Top model stays scoped", () => {
|
|
90
97
|
const rows = buildActivityInsights({
|
|
91
98
|
days: [{ date: "2026-03-07", skills: 0, mcp: 0, agents: 0, messages: 10, total: 0 }],
|
|
92
|
-
summary: {
|
|
99
|
+
summary: {
|
|
100
|
+
skills: 0,
|
|
101
|
+
mcp: 0,
|
|
102
|
+
agents: 1,
|
|
103
|
+
messages: 10,
|
|
104
|
+
codingAgents: 0,
|
|
105
|
+
chatAgents: 1,
|
|
106
|
+
longestStreak: 1,
|
|
107
|
+
},
|
|
93
108
|
providers: [
|
|
94
109
|
provider({
|
|
95
110
|
provider: "codex",
|
|
96
111
|
label: "Codex",
|
|
97
112
|
messageCount: 10,
|
|
113
|
+
agentCount: 1,
|
|
114
|
+
codingAgentCount: 0,
|
|
115
|
+
chatAgentCount: 1,
|
|
98
116
|
models: [{ model: "gpt-5.4", count: 10 }],
|
|
99
117
|
}),
|
|
100
118
|
],
|
|
101
119
|
providerFilter: "codex",
|
|
102
120
|
});
|
|
103
121
|
assert.equal(rows.length, ACTIVITY_LIST_LIMIT);
|
|
122
|
+
assert.equal(rows.find((r) => r.label === "Top provider")?.value, "—");
|
|
104
123
|
assert.equal(rows.find((r) => r.label === "Top model")?.value, "Gpt 5.4 · 100%");
|
|
124
|
+
assert.equal(rows.find((r) => r.label === "Coding vs chat")?.value, "0% coding");
|
|
105
125
|
});
|
|
106
126
|
|
|
107
127
|
it("uses dashes for zero denominators and falls back busiest day", () => {
|
|
108
128
|
const rows = buildActivityInsights({
|
|
109
129
|
days: [{ date: "2026-03-08", skills: 3, mcp: 1, agents: 2, messages: 0, total: 4 }],
|
|
110
|
-
summary: { skills: 3, mcp: 1, agents:
|
|
130
|
+
summary: { skills: 3, mcp: 1, agents: 2, messages: 0, codingAgents: 0, chatAgents: 0 },
|
|
111
131
|
providers: [],
|
|
112
132
|
providerFilter: "all",
|
|
113
133
|
locale: "en",
|
|
114
134
|
});
|
|
115
135
|
assert.equal(rows.find((r) => r.label === "Busiest day")?.value, "Mar 8 · 4 calls");
|
|
116
|
-
assert.equal(rows.find((r) => r.label === "Messages per agent")?.value, "
|
|
117
|
-
assert.equal(rows.find((r) => r.label === "Tools per message")?.value, "—");
|
|
136
|
+
assert.equal(rows.find((r) => r.label === "Messages per agent")?.value, "0");
|
|
118
137
|
assert.equal(rows.find((r) => r.label === "Coding vs chat")?.value, "—");
|
|
138
|
+
assert.equal(rows.find((r) => r.label === "Top provider")?.value, "—");
|
|
119
139
|
assert.equal(rows.find((r) => r.label === "Top model")?.value, "—");
|
|
120
140
|
assert.equal(rows.find((r) => r.label === "Peak weekday")?.value, "Sun");
|
|
121
141
|
});
|
package/shared/insights.ts
CHANGED
|
@@ -9,9 +9,10 @@ export type InsightSummary = {
|
|
|
9
9
|
mcp: number;
|
|
10
10
|
agents: number;
|
|
11
11
|
messages: number;
|
|
12
|
-
shell
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/** Agents with ≥1 coding op in-window (019: file write or mutating shell). */
|
|
13
|
+
codingAgents?: number;
|
|
14
|
+
/** Active non-coding agents (018); empty creations excluded. */
|
|
15
|
+
chatAgents?: number;
|
|
15
16
|
longestStreak?: number;
|
|
16
17
|
};
|
|
17
18
|
|
|
@@ -73,6 +74,25 @@ function formatBusiest(day: ActivityDay, locale: string): string {
|
|
|
73
74
|
return label;
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/** All view only: messages-weighted top provider. Filtered or empty → `—`. */
|
|
78
|
+
function topProviderValue(
|
|
79
|
+
providers: readonly ProviderUsageItem[],
|
|
80
|
+
providerFilter: string,
|
|
81
|
+
): string {
|
|
82
|
+
if (providerFilter !== "all") return "—";
|
|
83
|
+
const ranked = [...providers]
|
|
84
|
+
.filter((p) => p.messageCount > 0)
|
|
85
|
+
.sort(
|
|
86
|
+
(a, b) =>
|
|
87
|
+
b.messageCount - a.messageCount || a.provider.localeCompare(b.provider),
|
|
88
|
+
);
|
|
89
|
+
const top = ranked[0];
|
|
90
|
+
if (!top) return "—";
|
|
91
|
+
const total = ranked.reduce((sum, p) => sum + p.messageCount, 0);
|
|
92
|
+
const pct = total > 0 ? Math.round((top.messageCount / total) * 100) : 0;
|
|
93
|
+
return `${top.label} · ${pct}%`;
|
|
94
|
+
}
|
|
95
|
+
|
|
76
96
|
function topModelValue(
|
|
77
97
|
providers: readonly ProviderUsageItem[],
|
|
78
98
|
providerFilter: string,
|
|
@@ -97,12 +117,11 @@ function topModelValue(
|
|
|
97
117
|
return `${formatDisplayName(top[0])} · ${pct}%`;
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
/**
|
|
101
|
-
function codingVsChatValue(
|
|
102
|
-
const
|
|
103
|
-
const total = coding + messages;
|
|
120
|
+
/** Share of active agents that are coding (018); empty creations excluded. */
|
|
121
|
+
function codingVsChatValue(codingAgents: number, chatAgents: number): string {
|
|
122
|
+
const total = codingAgents + chatAgents;
|
|
104
123
|
if (total <= 0) return "—";
|
|
105
|
-
const pct = Math.round((
|
|
124
|
+
const pct = Math.round((codingAgents / total) * 100);
|
|
106
125
|
return `${pct}% coding`;
|
|
107
126
|
}
|
|
108
127
|
|
|
@@ -145,9 +164,9 @@ export function buildActivityInsights(input: {
|
|
|
145
164
|
const limit = input.limit ?? ACTIVITY_LIST_LIMIT;
|
|
146
165
|
const activeDays = input.days.filter(isActiveDay).length;
|
|
147
166
|
const busiest = pickBusiestDay(input.days);
|
|
148
|
-
const shell = input.summary.shell ?? 0;
|
|
149
|
-
const fileOps = (input.summary.fileReads ?? 0) + (input.summary.fileWrites ?? 0);
|
|
150
167
|
const longest = input.summary.longestStreak;
|
|
168
|
+
const codingAgents = input.summary.codingAgents ?? 0;
|
|
169
|
+
const chatAgents = input.summary.chatAgents ?? 0;
|
|
151
170
|
|
|
152
171
|
const rows: InsightRow[] = [
|
|
153
172
|
{ label: "Active days", value: String(activeDays) },
|
|
@@ -162,6 +181,14 @@ export function buildActivityInsights(input: {
|
|
|
162
181
|
label: "Busiest day",
|
|
163
182
|
value: busiest ? formatBusiest(busiest, locale) : "—",
|
|
164
183
|
},
|
|
184
|
+
{
|
|
185
|
+
label: "Peak weekday",
|
|
186
|
+
value: peakWeekdayValue(input.days, locale),
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
label: "Top provider",
|
|
190
|
+
value: topProviderValue(input.providers, input.providerFilter),
|
|
191
|
+
},
|
|
165
192
|
{
|
|
166
193
|
label: "Top model",
|
|
167
194
|
value: topModelValue(input.providers, input.providerFilter),
|
|
@@ -170,17 +197,9 @@ export function buildActivityInsights(input: {
|
|
|
170
197
|
label: "Messages per agent",
|
|
171
198
|
value: formatRatio(input.summary.messages, input.summary.agents),
|
|
172
199
|
},
|
|
173
|
-
{
|
|
174
|
-
label: "Tools per message",
|
|
175
|
-
value: formatRatio(input.summary.skills + input.summary.mcp, input.summary.messages),
|
|
176
|
-
},
|
|
177
200
|
{
|
|
178
201
|
label: "Coding vs chat",
|
|
179
|
-
value: codingVsChatValue(
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
label: "Peak weekday",
|
|
183
|
-
value: peakWeekdayValue(input.days, locale),
|
|
202
|
+
value: codingVsChatValue(codingAgents, chatAgents),
|
|
184
203
|
},
|
|
185
204
|
];
|
|
186
205
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { listAllAgentPages } from "./list-agent-pages.ts";
|
|
4
|
+
|
|
5
|
+
test("listAllAgentPages returns a single page when hasMore is false", async () => {
|
|
6
|
+
const pages: string[] = [];
|
|
7
|
+
const entries = await listAllAgentPages<string>(async (cursor) => {
|
|
8
|
+
pages.push(cursor ?? "start");
|
|
9
|
+
return { entries: ["a", "b"], pageInfo: { hasMore: false, nextCursor: null } };
|
|
10
|
+
});
|
|
11
|
+
assert.deepEqual(entries, ["a", "b"]);
|
|
12
|
+
assert.deepEqual(pages, ["start"]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("listAllAgentPages follows nextCursor until hasMore is false", async () => {
|
|
16
|
+
const pages: Array<string | undefined> = [];
|
|
17
|
+
const entries = await listAllAgentPages<number>(async (cursor) => {
|
|
18
|
+
pages.push(cursor);
|
|
19
|
+
if (cursor == null) {
|
|
20
|
+
return { entries: [1, 2], pageInfo: { hasMore: true, nextCursor: "p2" } };
|
|
21
|
+
}
|
|
22
|
+
if (cursor === "p2") {
|
|
23
|
+
return { entries: [3], pageInfo: { hasMore: true, nextCursor: "p3" } };
|
|
24
|
+
}
|
|
25
|
+
return { entries: [4, 5], pageInfo: { hasMore: false, nextCursor: null } };
|
|
26
|
+
});
|
|
27
|
+
assert.deepEqual(entries, [1, 2, 3, 4, 5]);
|
|
28
|
+
assert.deepEqual(pages, [undefined, "p2", "p3"]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("listAllAgentPages stops when hasMore without nextCursor", async () => {
|
|
32
|
+
const entries = await listAllAgentPages<string>(async () => ({
|
|
33
|
+
entries: ["only"],
|
|
34
|
+
pageInfo: { hasMore: true, nextCursor: null },
|
|
35
|
+
}));
|
|
36
|
+
assert.deepEqual(entries, ["only"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("listAllAgentPages throws when maxPages exceeded", async () => {
|
|
40
|
+
await assert.rejects(
|
|
41
|
+
() =>
|
|
42
|
+
listAllAgentPages(
|
|
43
|
+
async (cursor) => ({
|
|
44
|
+
entries: [cursor ?? "0"],
|
|
45
|
+
pageInfo: { hasMore: true, nextCursor: String(Number(cursor ?? 0) + 1) },
|
|
46
|
+
}),
|
|
47
|
+
{ maxPages: 3 },
|
|
48
|
+
),
|
|
49
|
+
/maxPages=3/,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drain cursor-based agent list pages until hasMore is false.
|
|
3
|
+
* Host default page size is typically ≤200; callers must not assume one page is complete.
|
|
4
|
+
*/
|
|
5
|
+
export type AgentListPageInfo = {
|
|
6
|
+
hasMore: boolean;
|
|
7
|
+
nextCursor: string | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type AgentListPage<T> = {
|
|
11
|
+
entries: ReadonlyArray<T>;
|
|
12
|
+
pageInfo: AgentListPageInfo;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function listAllAgentPages<T>(
|
|
16
|
+
listPage: (cursor: string | undefined) => Promise<AgentListPage<T>>,
|
|
17
|
+
options: { maxPages?: number } = {},
|
|
18
|
+
): Promise<T[]> {
|
|
19
|
+
const maxPages = options.maxPages ?? 100;
|
|
20
|
+
const all: T[] = [];
|
|
21
|
+
let cursor: string | undefined;
|
|
22
|
+
for (let page = 0; page < maxPages; page += 1) {
|
|
23
|
+
const result = await listPage(cursor);
|
|
24
|
+
all.push(...result.entries);
|
|
25
|
+
if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) {
|
|
26
|
+
return all;
|
|
27
|
+
}
|
|
28
|
+
cursor = result.pageInfo.nextCursor;
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`listAllAgentPages: exceeded maxPages=${maxPages}`);
|
|
31
|
+
}
|