@koinzhang/paseo-plugin-activity 0.1.0 → 0.3.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 +81 -0
- package/README.md +85 -0
- package/client/activity-heatmap.tsx +72 -14
- package/client/formatted-time.tsx +23 -0
- package/client/global-surface.tsx +24 -25
- package/client/hidden-pill-recheck.test.ts +33 -0
- package/client/hidden-pill-recheck.ts +22 -0
- package/client/panel.tsx +116 -107
- package/client/pill-directory.test.ts +92 -0
- package/client/pill-directory.ts +79 -0
- package/client/pill.tsx +23 -23
- package/client/range.ts +20 -0
- package/client/usage-popover.tsx +75 -84
- package/client/usage-query.tsx +8 -3
- package/client/usage-stats.tsx +7 -5
- package/client/use-agent-turn-end.ts +69 -0
- package/client/workspace/agent-row.tsx +167 -0
- package/client/workspace/agents-section.tsx +330 -0
- package/client/workspace/constants.ts +147 -0
- package/client/workspace/display-menu.tsx +116 -0
- package/client/workspace/filters.ts +30 -0
- package/client/workspace/list-host-agents.test.ts +45 -0
- package/client/workspace/list-host-agents.ts +90 -0
- package/client/workspace/panel.tsx +964 -0
- package/client/workspace/rank-section.tsx +131 -0
- package/client/workspace/running-indicator.tsx +54 -0
- package/client/workspace/status-cache.test.ts +62 -0
- package/client/workspace/status-cache.ts +19 -0
- package/client/workspace/terminal-preview.test.ts +17 -0
- package/client/workspace/terminal-preview.ts +10 -0
- package/client/workspace/terminals-section.tsx +155 -0
- package/client/workspace-panel.tsx +2 -0
- package/index.client.tsx +20 -13
- package/index.server.ts +13 -0
- package/package.json +9 -3
- package/server/agents.test.ts +36 -1
- package/server/agents.ts +9 -5
- package/server/background-sync.test.ts +14 -3
- package/server/background-sync.ts +16 -5
- package/server/handlers-query.test.ts +82 -3
- package/server/handlers.ts +89 -6
- package/server/messages.test.ts +8 -2
- package/server/skill-path.ts +3 -20
- 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 +41 -16
- package/shared/format.ts +26 -17
- package/shared/home-path.ts +19 -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 +336 -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,31 +1,56 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, it } from "node:test";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
formatActivityTime,
|
|
5
|
+
formatDisplayName,
|
|
6
|
+
formatLocalDateTime,
|
|
7
|
+
formatUpdatedAt,
|
|
8
|
+
} from "./format.ts";
|
|
4
9
|
|
|
5
10
|
const NOW = new Date(2026, 8, 18, 15, 30);
|
|
6
11
|
|
|
7
|
-
describe("
|
|
8
|
-
it("shows only
|
|
9
|
-
|
|
10
|
-
assert.
|
|
12
|
+
describe("formatActivityTime", () => {
|
|
13
|
+
it("shows only the time for the same local day", () => {
|
|
14
|
+
const text = formatActivityTime(new Date(2026, 8, 18, 9, 5).toISOString(), "en", NOW);
|
|
15
|
+
assert.match(text, /09:05|9:05/);
|
|
16
|
+
assert.doesNotMatch(text, /Sep/);
|
|
17
|
+
assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
|
|
11
18
|
});
|
|
12
19
|
|
|
13
|
-
it("adds
|
|
14
|
-
|
|
15
|
-
assert.
|
|
20
|
+
it("adds month/day for another day in the same year", () => {
|
|
21
|
+
const text = formatActivityTime(new Date(2026, 8, 17, 14, 2).toISOString(), "en", NOW);
|
|
22
|
+
assert.match(text, /Sep/);
|
|
23
|
+
assert.match(text, /17/);
|
|
24
|
+
assert.match(text, /14:02/);
|
|
25
|
+
assert.doesNotMatch(text, /2026/);
|
|
26
|
+
assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
|
|
16
27
|
});
|
|
17
28
|
|
|
18
|
-
it("
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
29
|
+
it("includes the year when the date is not this year", () => {
|
|
30
|
+
const text = formatActivityTime(new Date(2025, 11, 31, 23, 59).toISOString(), "en", NOW);
|
|
31
|
+
assert.match(text, /2025/);
|
|
32
|
+
assert.match(text, /Dec/);
|
|
33
|
+
assert.match(text, /23:59/);
|
|
34
|
+
assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
|
|
23
35
|
});
|
|
24
36
|
|
|
25
37
|
it("returns the placeholder for empty and keeps invalid input", () => {
|
|
26
|
-
assert.equal(
|
|
27
|
-
assert.equal(
|
|
28
|
-
assert.equal(
|
|
38
|
+
assert.equal(formatActivityTime(null, "en", NOW), "—");
|
|
39
|
+
assert.equal(formatActivityTime(undefined, "en", NOW), "—");
|
|
40
|
+
assert.equal(formatActivityTime("not-a-date", "en", NOW), "not-a-date");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("keeps formatUpdatedAt as an alias", () => {
|
|
44
|
+
assert.equal(formatUpdatedAt, formatActivityTime);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("formatLocalDateTime", () => {
|
|
49
|
+
it("defaults to English locale style", () => {
|
|
50
|
+
const text = formatLocalDateTime(new Date(2026, 8, 17, 14, 2).toISOString());
|
|
51
|
+
assert.match(text, /Sep/);
|
|
52
|
+
assert.match(text, /17/);
|
|
53
|
+
assert.match(text, /2026/);
|
|
29
54
|
});
|
|
30
55
|
});
|
|
31
56
|
|
package/shared/format.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/** Format stored ISO timestamps for UI / export in the local timezone + locale. */
|
|
2
|
-
export function formatLocalDateTime(
|
|
2
|
+
export function formatLocalDateTime(
|
|
3
|
+
iso: string | null | undefined,
|
|
4
|
+
locale = "en",
|
|
5
|
+
): string {
|
|
3
6
|
if (!iso) return "—";
|
|
4
7
|
const date = new Date(iso);
|
|
5
8
|
if (Number.isNaN(date.getTime())) return iso;
|
|
6
|
-
return date.toLocaleString(
|
|
9
|
+
return date.toLocaleString(locale, {
|
|
7
10
|
dateStyle: "medium",
|
|
8
11
|
timeStyle: "short",
|
|
9
12
|
});
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
function pad2(value: number): string {
|
|
13
|
-
return String(value).padStart(2, "0");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
15
|
/** Display-name prettifier: `-` / `_` → spaces, then Title Case each word. */
|
|
17
16
|
export function formatDisplayName(value: string): string {
|
|
18
17
|
const cleaned = value.replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim();
|
|
@@ -21,25 +20,35 @@ export function formatDisplayName(value: string): string {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* Activity UI timestamp: app locale + local timezone.
|
|
24
|
+
* Today → time only; same year → month/day + time; otherwise year + month/day + time.
|
|
26
25
|
*/
|
|
27
|
-
export function
|
|
26
|
+
export function formatActivityTime(
|
|
28
27
|
iso: string | null | undefined,
|
|
28
|
+
locale = "en",
|
|
29
29
|
now: Date = new Date(),
|
|
30
30
|
): string {
|
|
31
31
|
if (!iso) return "—";
|
|
32
32
|
const date = new Date(iso);
|
|
33
33
|
if (Number.isNaN(date.getTime())) return iso;
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
34
|
+
const sameDay =
|
|
36
35
|
date.getFullYear() === now.getFullYear() &&
|
|
37
36
|
date.getMonth() === now.getMonth() &&
|
|
38
|
-
date.getDate() === now.getDate()
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
date.getDate() === now.getDate();
|
|
38
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
39
|
+
hour: "numeric",
|
|
40
|
+
minute: "2-digit",
|
|
41
|
+
hour12: false,
|
|
42
|
+
};
|
|
43
|
+
if (!sameDay) {
|
|
44
|
+
options.month = "short";
|
|
45
|
+
options.day = "numeric";
|
|
46
|
+
if (date.getFullYear() !== now.getFullYear()) {
|
|
47
|
+
options.year = "numeric";
|
|
48
|
+
}
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
if (date.getFullYear() === now.getFullYear()) return `${monthDay} ${time}`;
|
|
44
|
-
return `${date.getFullYear()}-${monthDay} ${time}`;
|
|
50
|
+
return date.toLocaleString(locale, options);
|
|
45
51
|
}
|
|
52
|
+
|
|
53
|
+
/** @deprecated Prefer `formatActivityTime`. */
|
|
54
|
+
export const formatUpdatedAt = formatActivityTime;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Collapse `homeDir` prefix to `~` so RPC/UI never expose `/Users/…`. */
|
|
2
|
+
export function collapseHomePath(path: string, homeDir: string): string {
|
|
3
|
+
const trimmed = path.trim();
|
|
4
|
+
if (!trimmed || !homeDir) return trimmed;
|
|
5
|
+
if (trimmed === homeDir) return "~";
|
|
6
|
+
const prefix = homeDir.endsWith("/") ? homeDir : `${homeDir}/`;
|
|
7
|
+
if (trimmed.startsWith(prefix)) {
|
|
8
|
+
return `~/${trimmed.slice(prefix.length)}`;
|
|
9
|
+
}
|
|
10
|
+
// Case-insensitive match (macOS default FS); preserve the remainder as-is.
|
|
11
|
+
const lower = trimmed.toLowerCase();
|
|
12
|
+
const homeLower = homeDir.toLowerCase();
|
|
13
|
+
if (lower === homeLower) return "~";
|
|
14
|
+
const prefixLower = homeLower.endsWith("/") ? homeLower : `${homeLower}/`;
|
|
15
|
+
if (lower.startsWith(prefixLower)) {
|
|
16
|
+
return `~/${trimmed.slice(prefixLower.length)}`;
|
|
17
|
+
}
|
|
18
|
+
return trimmed;
|
|
19
|
+
}
|
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
|
+
}
|