@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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
|
|
4
|
+
import { formatDisplayName, formatLocalDateTime } from "../../shared/format.ts";
|
|
5
|
+
import type { McpByToolItem, SkillByNameItem } from "../../shared/usage.ts";
|
|
6
|
+
import { RANK_ROW_ESTIMATE } from "./constants.ts";
|
|
7
|
+
|
|
8
|
+
type RankKind = "skills" | "mcp";
|
|
9
|
+
|
|
10
|
+
function rankTitle(kind: RankKind): string {
|
|
11
|
+
return kind === "skills" ? "Skills" : "MCP";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function rankAction(kind: RankKind): { icon: "Sparkles" | "Plug"; accessibilityLabel: string } {
|
|
15
|
+
return kind === "skills"
|
|
16
|
+
? { icon: "Plug", accessibilityLabel: "Show most used MCP" }
|
|
17
|
+
: { icon: "Sparkles", accessibilityLabel: "Show most used skills" };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function CountText({
|
|
21
|
+
value,
|
|
22
|
+
styles,
|
|
23
|
+
}: {
|
|
24
|
+
value: number | string;
|
|
25
|
+
styles: { countText: TextStyle };
|
|
26
|
+
}): ReactNode {
|
|
27
|
+
return <Text style={styles.countText}>{value}</Text>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type RankSectionStyles = {
|
|
31
|
+
sectionHeaderRow: ViewStyle;
|
|
32
|
+
sectionTitle: TextStyle;
|
|
33
|
+
titleAction: ViewStyle;
|
|
34
|
+
panel: ViewStyle;
|
|
35
|
+
listRow: ViewStyle;
|
|
36
|
+
listMain: ViewStyle;
|
|
37
|
+
listTitle: TextStyle;
|
|
38
|
+
listMeta: TextStyle;
|
|
39
|
+
countText: TextStyle;
|
|
40
|
+
empty: TextStyle;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function RankSection({
|
|
44
|
+
rankKind,
|
|
45
|
+
onToggleKind,
|
|
46
|
+
skillItems,
|
|
47
|
+
mcpItems,
|
|
48
|
+
mutedColor,
|
|
49
|
+
styles,
|
|
50
|
+
}: {
|
|
51
|
+
rankKind: RankKind;
|
|
52
|
+
onToggleKind: () => void;
|
|
53
|
+
skillItems: ReadonlyArray<SkillByNameItem>;
|
|
54
|
+
mcpItems: ReadonlyArray<McpByToolItem>;
|
|
55
|
+
mutedColor: string;
|
|
56
|
+
styles: RankSectionStyles;
|
|
57
|
+
}): ReactNode {
|
|
58
|
+
return (
|
|
59
|
+
<View style={{ gap: 12 }}>
|
|
60
|
+
<View style={styles.sectionHeaderRow}>
|
|
61
|
+
<Text style={styles.sectionTitle}>{rankTitle(rankKind)}</Text>
|
|
62
|
+
<Pressable
|
|
63
|
+
accessibilityRole="button"
|
|
64
|
+
accessibilityLabel={rankAction(rankKind).accessibilityLabel}
|
|
65
|
+
hitSlop={8}
|
|
66
|
+
onPress={onToggleKind}
|
|
67
|
+
style={styles.titleAction}
|
|
68
|
+
>
|
|
69
|
+
<Icon name={rankAction(rankKind).icon} size={16} color={mutedColor} />
|
|
70
|
+
</Pressable>
|
|
71
|
+
</View>
|
|
72
|
+
<View
|
|
73
|
+
style={[
|
|
74
|
+
styles.panel,
|
|
75
|
+
{
|
|
76
|
+
minHeight: Math.max(skillItems.length, mcpItems.length, 1) * RANK_ROW_ESTIMATE,
|
|
77
|
+
},
|
|
78
|
+
]}
|
|
79
|
+
>
|
|
80
|
+
{rankKind === "skills"
|
|
81
|
+
? skillItems.map((item) => (
|
|
82
|
+
<View key={item.skillName} style={styles.listRow}>
|
|
83
|
+
<Icon name="Sparkles" size={18} color={mutedColor} />
|
|
84
|
+
<View style={styles.listMain}>
|
|
85
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
86
|
+
{formatDisplayName(item.skillName)}
|
|
87
|
+
</Text>
|
|
88
|
+
<Text style={styles.listMeta}>
|
|
89
|
+
Last {formatLocalDateTime(item.lastUsedAt)}
|
|
90
|
+
</Text>
|
|
91
|
+
</View>
|
|
92
|
+
<CountText value={item.total} styles={styles} />
|
|
93
|
+
</View>
|
|
94
|
+
))
|
|
95
|
+
: mcpItems.map((item) => (
|
|
96
|
+
<View key={`${item.server}.${item.tool}`} style={styles.listRow}>
|
|
97
|
+
<Icon name="Plug" size={18} color={mutedColor} />
|
|
98
|
+
<View style={styles.listMain}>
|
|
99
|
+
<Text style={styles.listTitle} numberOfLines={1}>
|
|
100
|
+
{formatDisplayName(`${item.server}.${item.tool}`)}
|
|
101
|
+
</Text>
|
|
102
|
+
<Text style={styles.listMeta}>
|
|
103
|
+
{item.failures > 0
|
|
104
|
+
? `${item.failures} failed`
|
|
105
|
+
: item.lastUsedAt
|
|
106
|
+
? `Last ${formatLocalDateTime(item.lastUsedAt)}`
|
|
107
|
+
: "—"}
|
|
108
|
+
</Text>
|
|
109
|
+
</View>
|
|
110
|
+
<CountText value={item.count} styles={styles} />
|
|
111
|
+
</View>
|
|
112
|
+
))}
|
|
113
|
+
{(rankKind === "skills" ? skillItems.length : mcpItems.length) === 0 ? (
|
|
114
|
+
<Text style={styles.empty}>
|
|
115
|
+
{rankKind === "skills" ? "No skills yet" : "No MCP yet"}
|
|
116
|
+
</Text>
|
|
117
|
+
) : null}
|
|
118
|
+
</View>
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
-
import { copyText } from "@getpaseo/plugin/client/react-native";
|
|
3
2
|
import { GlobalUsageSurface } from "./client/global-surface.tsx";
|
|
4
3
|
import { UsagePanel } from "./client/panel.tsx";
|
|
5
4
|
import { contributePills } from "./client/pill.tsx";
|
|
6
|
-
import {
|
|
5
|
+
import { WorkspaceActivityPanel } from "./client/workspace-panel.tsx";
|
|
7
6
|
|
|
8
7
|
const GLOBAL_SURFACE_ID = "activity";
|
|
9
8
|
|
|
@@ -24,9 +23,18 @@ export default function contribute(client: PluginClientContext) {
|
|
|
24
23
|
Component: UsagePanel,
|
|
25
24
|
});
|
|
26
25
|
|
|
26
|
+
client.addWorkspacePanel({
|
|
27
|
+
id: "workspace-activity",
|
|
28
|
+
title: "Activity",
|
|
29
|
+
icon: "Activity",
|
|
30
|
+
context: "workspace",
|
|
31
|
+
locations: ["explorer"],
|
|
32
|
+
Component: WorkspaceActivityPanel,
|
|
33
|
+
});
|
|
34
|
+
|
|
27
35
|
client.addCommandCenterItem({
|
|
28
36
|
id: "open-usage-global",
|
|
29
|
-
title: "
|
|
37
|
+
title: "Activity",
|
|
30
38
|
icon: "Activity",
|
|
31
39
|
keywords: ["activity", "tool", "usage", "provider", "all", "global", "sidebar"],
|
|
32
40
|
context: "global",
|
|
@@ -37,9 +45,9 @@ export default function contribute(client: PluginClientContext) {
|
|
|
37
45
|
|
|
38
46
|
client.addCommandCenterItem({
|
|
39
47
|
id: "open-usage",
|
|
40
|
-
title: "Activity",
|
|
48
|
+
title: "Agent Activity",
|
|
41
49
|
icon: "Activity",
|
|
42
|
-
keywords: ["activity", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
50
|
+
keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
43
51
|
context: "agent",
|
|
44
52
|
onSelect: ({ openPanel }) => {
|
|
45
53
|
openPanel("usage");
|
|
@@ -47,14 +55,13 @@ export default function contribute(client: PluginClientContext) {
|
|
|
47
55
|
});
|
|
48
56
|
|
|
49
57
|
client.addCommandCenterItem({
|
|
50
|
-
id: "
|
|
51
|
-
title: "
|
|
52
|
-
icon: "
|
|
53
|
-
keywords: ["
|
|
54
|
-
context: "
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
await copyText(result.markdown);
|
|
58
|
+
id: "open-workspace-activity",
|
|
59
|
+
title: "Workspace Activity",
|
|
60
|
+
icon: "Activity",
|
|
61
|
+
keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
62
|
+
context: "workspace",
|
|
63
|
+
onSelect({ openPanel }) {
|
|
64
|
+
openPanel("workspace-activity", { location: "explorer" });
|
|
58
65
|
},
|
|
59
66
|
});
|
|
60
67
|
|
package/index.server.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
4
4
|
import {
|
|
5
5
|
createActivityByDayHandler,
|
|
6
|
+
createAgentsHandler,
|
|
6
7
|
createByProviderHandler,
|
|
7
8
|
createExportHandler,
|
|
8
9
|
createListHandler,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
createReadSkillHandler,
|
|
11
12
|
createSkillsByNameHandler,
|
|
12
13
|
createSummaryHandler,
|
|
14
|
+
createUnarchiveAgentHandler,
|
|
13
15
|
} from "./server/handlers.ts";
|
|
14
16
|
import { agentRowFromHook } from "./server/agents.ts";
|
|
15
17
|
import { ingestTimeline, ingestUserMessages } from "./server/ingest.ts";
|
|
@@ -17,6 +19,8 @@ import { resolveAgentModel } from "./server/resolve-model.ts";
|
|
|
17
19
|
import { createUsageStore } from "./server/store.ts";
|
|
18
20
|
import {
|
|
19
21
|
usageActivityByDayRpc,
|
|
22
|
+
usageAgentsRpc,
|
|
23
|
+
usageAgentUnarchiveRpc,
|
|
20
24
|
usageByProviderRpc,
|
|
21
25
|
usageExportRpc,
|
|
22
26
|
usageListRpc,
|
|
@@ -25,11 +29,13 @@ import {
|
|
|
25
29
|
usageSkillsByNameRpc,
|
|
26
30
|
usageSummaryRpc,
|
|
27
31
|
} from "./shared/usage.ts";
|
|
32
|
+
import { explorerAgentDisplaySettings } from "./shared/explorer-agent-display.ts";
|
|
28
33
|
|
|
29
34
|
export default function contribute(server: PluginServerContext) {
|
|
30
35
|
const store = createUsageStore();
|
|
31
36
|
const background = createBackgroundSync(store);
|
|
32
37
|
console.log(`[activity] store ready (driver=${store.driver})`);
|
|
38
|
+
server.registerSettings(explorerAgentDisplaySettings);
|
|
33
39
|
|
|
34
40
|
server.handle(usageSummaryRpc, (input, context) => {
|
|
35
41
|
void background.request(context.paseo);
|
|
@@ -51,6 +57,11 @@ export default function contribute(server: PluginServerContext) {
|
|
|
51
57
|
void background.request(context.paseo);
|
|
52
58
|
return createByProviderHandler(store)(input);
|
|
53
59
|
});
|
|
60
|
+
server.handle(usageAgentsRpc, (input, context) => {
|
|
61
|
+
void background.request(context.paseo);
|
|
62
|
+
return createAgentsHandler(store)(input);
|
|
63
|
+
});
|
|
64
|
+
server.handle(usageAgentUnarchiveRpc, createUnarchiveAgentHandler(store));
|
|
54
65
|
server.handle(usageActivityByDayRpc, (input, context) => {
|
|
55
66
|
void background.request(context.paseo);
|
|
56
67
|
return createActivityByDayHandler(store)(input);
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koinzhang/paseo-plugin-activity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Local usage analytics for Paseo: tool calls, agents, messages, and model usage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/koinzhang/paseo-plugins.git",
|
|
10
|
+
"directory": "activity"
|
|
11
|
+
},
|
|
7
12
|
"files": [
|
|
8
13
|
"paseo-plugin.json",
|
|
14
|
+
"CHANGELOG.md",
|
|
9
15
|
"index.client.ts",
|
|
10
16
|
"index.client.tsx",
|
|
11
17
|
"index.server.ts",
|
|
@@ -16,7 +22,7 @@
|
|
|
16
22
|
],
|
|
17
23
|
"scripts": {
|
|
18
24
|
"typecheck": "tsc --noEmit",
|
|
19
|
-
"test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/pill-data-cache.test.ts client/rank-color.test.ts client/provider-filter.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts"
|
|
25
|
+
"test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/pill-data-cache.test.ts client/rank-color.test.ts client/provider-filter.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts"
|
|
20
26
|
},
|
|
21
27
|
"devDependencies": {
|
|
22
28
|
"@getpaseo/plugin": "0.8.0",
|
package/server/agents.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 { agentsFromToolCalls, agentRowFromHook } from "./agents.ts";
|
|
3
|
+
import { agentsFromToolCalls, agentRowFromHook, agentRowFromSnapshot } from "./agents.ts";
|
|
4
4
|
import type { ToolCallRow } from "./store.ts";
|
|
5
5
|
|
|
6
6
|
function row(over: Partial<ToolCallRow> = {}): ToolCallRow {
|
|
@@ -65,3 +65,22 @@ describe("agentRowFromHook", () => {
|
|
|
65
65
|
assert.equal(row.createdAt, "2026-09-18T00:00:00.000Z");
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
describe("agentRowFromSnapshot", () => {
|
|
70
|
+
it("passes through archivedAt", () => {
|
|
71
|
+
const active = agentRowFromSnapshot({
|
|
72
|
+
id: "a1",
|
|
73
|
+
provider: "claude",
|
|
74
|
+
createdAt: "2026-09-18T00:00:00.000Z",
|
|
75
|
+
archivedAt: null,
|
|
76
|
+
});
|
|
77
|
+
assert.equal(active.archivedAt, null);
|
|
78
|
+
const archived = agentRowFromSnapshot({
|
|
79
|
+
id: "a2",
|
|
80
|
+
provider: "claude",
|
|
81
|
+
createdAt: "2026-09-18T00:00:00.000Z",
|
|
82
|
+
archivedAt: "2026-09-19T00:00:00.000Z",
|
|
83
|
+
});
|
|
84
|
+
assert.equal(archived.archivedAt, "2026-09-19T00:00:00.000Z");
|
|
85
|
+
});
|
|
86
|
+
});
|
package/server/agents.ts
CHANGED
|
@@ -29,6 +29,7 @@ export function agentRowFromSnapshot(agent: {
|
|
|
29
29
|
provider: string;
|
|
30
30
|
title?: string | null;
|
|
31
31
|
createdAt: string;
|
|
32
|
+
archivedAt?: string | null;
|
|
32
33
|
}): AgentRow {
|
|
33
34
|
const updatedAt = nowIso();
|
|
34
35
|
return {
|
|
@@ -38,7 +39,7 @@ export function agentRowFromSnapshot(agent: {
|
|
|
38
39
|
provider: agent.provider,
|
|
39
40
|
title: agent.title ?? null,
|
|
40
41
|
createdAt: agent.createdAt,
|
|
41
|
-
archivedAt: null,
|
|
42
|
+
archivedAt: agent.archivedAt ?? null,
|
|
42
43
|
updatedAt,
|
|
43
44
|
};
|
|
44
45
|
}
|
|
@@ -14,7 +14,14 @@ function fixture() {
|
|
|
14
14
|
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
15
15
|
const path = join(dir, "checkpoints.json");
|
|
16
16
|
const agent = { id: "a1", provider: "codex", createdAt: "2026-09-19", updatedAt: "2026-09-19", lastUserMessageAt: null };
|
|
17
|
-
const paseo = {
|
|
17
|
+
const paseo = {
|
|
18
|
+
agents: {
|
|
19
|
+
list: async () => ({
|
|
20
|
+
entries: [{ agent }],
|
|
21
|
+
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
} as unknown as PaseoApi;
|
|
18
25
|
return { store, path, agent, paseo, cleanup() { store.close(); rmSync(dir, { recursive: true, force: true }); } };
|
|
19
26
|
}
|
|
20
27
|
|
|
@@ -62,7 +69,8 @@ test("concurrent triggers share one scan; stopping prevents completion checkpoin
|
|
|
62
69
|
try {
|
|
63
70
|
const first = sync.request(f.paseo);
|
|
64
71
|
assert.equal(sync.request(f.paseo), first);
|
|
65
|
-
|
|
72
|
+
// listAllAgentPages awaits agents.list before scan starts — drain microtasks.
|
|
73
|
+
for (let i = 0; i < 20 && scans === 0; i++) await Promise.resolve();
|
|
66
74
|
assert.equal(scans, 1);
|
|
67
75
|
sync.stop(); release(); await first;
|
|
68
76
|
assert.equal(existsSync(f.path), false);
|
|
@@ -121,7 +129,10 @@ test("stopping after agents.list prevents directory writes", async () => {
|
|
|
121
129
|
agents: {
|
|
122
130
|
list: async () => {
|
|
123
131
|
await listGate;
|
|
124
|
-
return {
|
|
132
|
+
return {
|
|
133
|
+
entries: [{ agent: f.agent }],
|
|
134
|
+
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
|
135
|
+
};
|
|
125
136
|
},
|
|
126
137
|
},
|
|
127
138
|
} as unknown as PaseoApi;
|
|
@@ -2,6 +2,7 @@ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
4
|
import { LOG_PREFIX } from "../shared/plugin-id.ts";
|
|
5
|
+
import { listAllAgentPages } from "../shared/list-agent-pages.ts";
|
|
5
6
|
import type { UsageStore } from "./store.ts";
|
|
6
7
|
import { defaultDataDir } from "./store.ts";
|
|
7
8
|
import { agentRowFromSnapshot, agentsFromToolCalls } from "./agents.ts";
|
|
@@ -12,6 +13,16 @@ type PaseoApi = PluginHandlerContext["paseo"];
|
|
|
12
13
|
// Bump when historical ingestion semantics change, not on UI-only releases.
|
|
13
14
|
const BACKFILL_VERSION = 1;
|
|
14
15
|
const CHECK_INTERVAL_MS = 5 * 60_000;
|
|
16
|
+
const AGENT_LIST_PAGE_LIMIT = 200;
|
|
17
|
+
|
|
18
|
+
async function listAllAgents(paseo: PaseoApi) {
|
|
19
|
+
return listAllAgentPages(async (cursor) => {
|
|
20
|
+
const result = await paseo.agents.list({
|
|
21
|
+
page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
22
|
+
});
|
|
23
|
+
return { entries: result.entries, pageInfo: result.pageInfo };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
15
26
|
|
|
16
27
|
export function createBackgroundSync(store: UsageStore, options: {
|
|
17
28
|
path?: string;
|
|
@@ -45,14 +56,14 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
async function check(paseo: PaseoApi) {
|
|
48
|
-
const
|
|
59
|
+
const listedEntries = await listAllAgents(paseo);
|
|
49
60
|
if (controller.signal.aborted) return;
|
|
50
61
|
// Directory synchronization belongs to the background task, never a UI read.
|
|
51
|
-
store.upsertAgents(
|
|
62
|
+
store.upsertAgents(listedEntries.map(({ agent }) => agentRowFromSnapshot(agent)));
|
|
52
63
|
const known = new Set(store.selectAgents().map(agent => agent.agentId));
|
|
53
64
|
store.upsertAgents(agentsFromToolCalls(store.select()).filter(agent => !known.has(agent.agentId)));
|
|
54
65
|
|
|
55
|
-
const liveIds = new Set(
|
|
66
|
+
const liveIds = new Set(listedEntries.map(({ agent }) => agent.id));
|
|
56
67
|
const pruned: Record<string, string> = Object.create(null);
|
|
57
68
|
for (const [id, stamp] of Object.entries(checkpoints)) {
|
|
58
69
|
if (liveIds.has(id)) pruned[id] = stamp;
|
|
@@ -61,11 +72,11 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
61
72
|
persistCheckpoints(pruned);
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
for (const { agent } of
|
|
75
|
+
for (const { agent } of listedEntries) {
|
|
65
76
|
if (controller.signal.aborted) return;
|
|
66
77
|
const stamp = `${agent.updatedAt}:${agent.lastUserMessageAt ?? ""}`;
|
|
67
78
|
if (checkpoints[agent.id] === stamp) continue;
|
|
68
|
-
const result = await scan(store, paseo, [agent.id], controller.signal,
|
|
79
|
+
const result = await scan(store, paseo, [agent.id], controller.signal, listedEntries);
|
|
69
80
|
if (controller.signal.aborted) return;
|
|
70
81
|
if (result.errors.length || result.syncedAgents !== 1) {
|
|
71
82
|
console.error("[activity] background history scan incomplete", agent.id, result.errors);
|
|
@@ -6,6 +6,7 @@ import { test } from "node:test";
|
|
|
6
6
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
7
7
|
import {
|
|
8
8
|
createActivityByDayHandler,
|
|
9
|
+
createAgentsHandler,
|
|
9
10
|
createByProviderHandler,
|
|
10
11
|
createSkillsByNameHandler,
|
|
11
12
|
} from "./handlers.ts";
|
|
@@ -65,6 +66,63 @@ test("by-provider and activity-by-day read the local store only", async () => {
|
|
|
65
66
|
}
|
|
66
67
|
});
|
|
67
68
|
|
|
69
|
+
test("usage.agents filters by workspace and merges the registry", async () => {
|
|
70
|
+
const dir = mkdtempSync(join(tmpdir(), "fast-agents-"));
|
|
71
|
+
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
72
|
+
try {
|
|
73
|
+
store.upsertMany([
|
|
74
|
+
row({ agentId: "a1", callId: "c1", workspaceId: "w1" }),
|
|
75
|
+
row({ agentId: "a2", callId: "c2", workspaceId: "w2" }),
|
|
76
|
+
]);
|
|
77
|
+
store.upsertAgents([
|
|
78
|
+
{
|
|
79
|
+
agentId: "a1",
|
|
80
|
+
workspaceId: "w1",
|
|
81
|
+
parentAgentId: null,
|
|
82
|
+
provider: "codex",
|
|
83
|
+
title: "Alpha",
|
|
84
|
+
createdAt: "2026-09-19T10:00:00.000Z",
|
|
85
|
+
archivedAt: null,
|
|
86
|
+
updatedAt: "2026-09-19T10:00:00.000Z",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
agentId: "a2",
|
|
90
|
+
workspaceId: "w2",
|
|
91
|
+
parentAgentId: null,
|
|
92
|
+
provider: "codex",
|
|
93
|
+
title: "Beta",
|
|
94
|
+
createdAt: "2026-09-19T10:00:00.000Z",
|
|
95
|
+
archivedAt: null,
|
|
96
|
+
updatedAt: "2026-09-19T10:00:00.000Z",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
agentId: "a3",
|
|
100
|
+
workspaceId: "w1",
|
|
101
|
+
parentAgentId: null,
|
|
102
|
+
provider: "codex",
|
|
103
|
+
title: "Archived",
|
|
104
|
+
createdAt: "2026-09-19T09:00:00.000Z",
|
|
105
|
+
archivedAt: "2026-09-19T11:00:00.000Z",
|
|
106
|
+
updatedAt: "2026-09-19T11:00:00.000Z",
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
const result = await createAgentsHandler(store)({ workspaceId: "w1" });
|
|
110
|
+
assert.deepEqual(
|
|
111
|
+
result.items.map((item) => item.agentId),
|
|
112
|
+
["a1", "a3"],
|
|
113
|
+
);
|
|
114
|
+
assert.equal(result.items[0]?.title, "Alpha");
|
|
115
|
+
assert.equal(result.items[0]?.callCount, 1);
|
|
116
|
+
assert.equal(result.items[0]?.skillCalls, 1);
|
|
117
|
+
assert.equal(result.items[0]?.archivedAt, null);
|
|
118
|
+
assert.equal(result.items[0]?.updatedAt, "2026-09-19T10:00:00.000Z");
|
|
119
|
+
assert.equal(result.items[1]?.archivedAt, "2026-09-19T11:00:00.000Z");
|
|
120
|
+
} finally {
|
|
121
|
+
store.close();
|
|
122
|
+
rmSync(dir, { recursive: true, force: true });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
68
126
|
test("skills-by-name never awaits agent.refresh", async () => {
|
|
69
127
|
const dir = mkdtempSync(join(tmpdir(), "fast-skills-"));
|
|
70
128
|
const store = createUsageStore({ dir, driver: "sqlite" });
|
package/server/handlers.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import { basename, dirname, resolve, sep } from "node:path";
|
|
6
6
|
import { realpathSync, statSync } from "node:fs";
|
|
7
7
|
import {
|
|
8
|
+
aggregateAgents,
|
|
8
9
|
aggregateByProvider,
|
|
9
10
|
aggregateMcpByTool,
|
|
10
11
|
aggregateShellTop,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
isFileWrite,
|
|
15
16
|
isShellCall,
|
|
16
17
|
usageActivityByDayRpc,
|
|
18
|
+
usageAgentsRpc,
|
|
19
|
+
usageAgentUnarchiveRpc,
|
|
17
20
|
usageByProviderRpc,
|
|
18
21
|
usageExportRpc,
|
|
19
22
|
usageListRpc,
|
|
@@ -22,6 +25,7 @@ import {
|
|
|
22
25
|
usageSkillsByNameRpc,
|
|
23
26
|
usageSummaryRpc,
|
|
24
27
|
} from "../shared/usage.ts";
|
|
28
|
+
import { listAllAgentPages } from "../shared/list-agent-pages.ts";
|
|
25
29
|
import { DEFAULT_SKILL_ROOTS, matchSkillFile } from "../shared/classify.ts";
|
|
26
30
|
import { buildHomeSkillRoots, buildSkillRoots, toolCallToRow, ingestUserMessages } from "./ingest.ts";
|
|
27
31
|
import { normalizeModelId } from "./resolve-model.ts";
|
|
@@ -36,6 +40,12 @@ import { formatLocalDateTime } from "../shared/format.ts";
|
|
|
36
40
|
import { agentRowFromSnapshot } from "./agents.ts";
|
|
37
41
|
import { readFile } from "node:fs/promises";
|
|
38
42
|
|
|
43
|
+
const AGENT_LIST_PAGE_LIMIT = 200;
|
|
44
|
+
import { execFile } from "node:child_process";
|
|
45
|
+
import { promisify } from "node:util";
|
|
46
|
+
|
|
47
|
+
const execFileAsync = promisify(execFile);
|
|
48
|
+
|
|
39
49
|
type PaseoApi = PluginHandlerContext["paseo"];
|
|
40
50
|
|
|
41
51
|
export type UsageSummary = RpcOutput<typeof usageSummaryRpc>;
|
|
@@ -82,6 +92,7 @@ export function summarizeRows(rows: readonly ToolCallRow[]): UsageSummary {
|
|
|
82
92
|
mcpCalls,
|
|
83
93
|
mcpFailures,
|
|
84
94
|
toolCallsByKind,
|
|
95
|
+
messageCount: 0,
|
|
85
96
|
};
|
|
86
97
|
}
|
|
87
98
|
|
|
@@ -93,7 +104,10 @@ export function createSummaryHandler(store: UsageStore) {
|
|
|
93
104
|
from: input.from,
|
|
94
105
|
to: input.to,
|
|
95
106
|
};
|
|
96
|
-
return
|
|
107
|
+
return {
|
|
108
|
+
...summarizeRows(store.select(filter)),
|
|
109
|
+
messageCount: store.selectUserMessages(filter).length,
|
|
110
|
+
};
|
|
97
111
|
};
|
|
98
112
|
}
|
|
99
113
|
|
|
@@ -213,6 +227,56 @@ export function createByProviderHandler(store: UsageStore) {
|
|
|
213
227
|
};
|
|
214
228
|
}
|
|
215
229
|
|
|
230
|
+
export function createAgentsHandler(store: UsageStore) {
|
|
231
|
+
return async (
|
|
232
|
+
input: RpcInput<typeof usageAgentsRpc>,
|
|
233
|
+
): Promise<RpcOutput<typeof usageAgentsRpc>> => {
|
|
234
|
+
const rows = store.select({
|
|
235
|
+
workspaceId: input.workspaceId,
|
|
236
|
+
from: input.from,
|
|
237
|
+
to: input.to,
|
|
238
|
+
});
|
|
239
|
+
// Registry lookup ignores the window so titles stay available for agents
|
|
240
|
+
// created before it; activity counts still come from the filtered rows.
|
|
241
|
+
const agents = store.selectAgents({ workspaceId: input.workspaceId });
|
|
242
|
+
const messages = store.selectUserMessages({
|
|
243
|
+
workspaceId: input.workspaceId,
|
|
244
|
+
from: input.from,
|
|
245
|
+
to: input.to,
|
|
246
|
+
});
|
|
247
|
+
return { items: aggregateAgents(rows, agents, messages) };
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Host Unarchive ≡ refreshAgent; CLI surface is `paseo agent reload`. */
|
|
252
|
+
export function createUnarchiveAgentHandler(store: UsageStore) {
|
|
253
|
+
return async (
|
|
254
|
+
input: RpcInput<typeof usageAgentUnarchiveRpc>,
|
|
255
|
+
): Promise<RpcOutput<typeof usageAgentUnarchiveRpc>> => {
|
|
256
|
+
try {
|
|
257
|
+
await execFileAsync("paseo", ["agent", "reload", input.agentId], {
|
|
258
|
+
timeout: 120_000,
|
|
259
|
+
maxBuffer: 1024 * 1024,
|
|
260
|
+
});
|
|
261
|
+
} catch (error) {
|
|
262
|
+
const err = error as { stderr?: string; message?: string };
|
|
263
|
+
const detail = (err.stderr?.trim() || err.message || String(error)).trim();
|
|
264
|
+
throw new Error(detail || `Failed to unarchive agent ${input.agentId}`);
|
|
265
|
+
}
|
|
266
|
+
const existing = store.getAgent(input.agentId);
|
|
267
|
+
if (existing) {
|
|
268
|
+
store.upsertAgents([
|
|
269
|
+
{
|
|
270
|
+
...existing,
|
|
271
|
+
archivedAt: null,
|
|
272
|
+
updatedAt: new Date().toISOString(),
|
|
273
|
+
},
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
return { agentId: input.agentId, ok: true };
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
216
280
|
export function createActivityByDayHandler(store: UsageStore) {
|
|
217
281
|
return async (
|
|
218
282
|
input: RpcInput<typeof usageActivityByDayRpc>,
|
|
@@ -456,7 +520,14 @@ export async function resyncAgents(
|
|
|
456
520
|
const homeDir = homedir();
|
|
457
521
|
const listed = listedEntries
|
|
458
522
|
? { entries: listedEntries }
|
|
459
|
-
:
|
|
523
|
+
: {
|
|
524
|
+
entries: await listAllAgentPages(async (cursor) => {
|
|
525
|
+
const result = await paseo.agents.list({
|
|
526
|
+
page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
527
|
+
});
|
|
528
|
+
return { entries: result.entries, pageInfo: result.pageInfo };
|
|
529
|
+
}),
|
|
530
|
+
};
|
|
460
531
|
const targets = listed.entries
|
|
461
532
|
.map((entry) => entry.agent)
|
|
462
533
|
.filter((agent) => !agentIds || agentIds.includes(agent.id));
|
package/server/messages.test.ts
CHANGED
|
@@ -96,7 +96,10 @@ test("resync paginates messages idempotently; query handlers use stored messages
|
|
|
96
96
|
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
97
97
|
let calls = 0;
|
|
98
98
|
const paseo = { agents: {
|
|
99
|
-
list: async () => ({
|
|
99
|
+
list: async () => ({
|
|
100
|
+
entries: [{ agent: { ...agent, createdAt: earlier } }],
|
|
101
|
+
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
|
102
|
+
}),
|
|
100
103
|
ref: () => ({ timeline: { refetch: async (input: { direction: string }) => {
|
|
101
104
|
calls++;
|
|
102
105
|
const tail = input.direction === "tail";
|
|
@@ -132,7 +135,10 @@ test("canceling an in-flight canonical scan prevents writes after the store clos
|
|
|
132
135
|
const started = new Promise<void>(resolve => { entered = resolve; });
|
|
133
136
|
const gate = new Promise<void>(resolve => { release = resolve; });
|
|
134
137
|
const paseo = { agents: {
|
|
135
|
-
list: async () => ({
|
|
138
|
+
list: async () => ({
|
|
139
|
+
entries: [{ agent: { ...agent, createdAt: earlier } }],
|
|
140
|
+
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
|
141
|
+
}),
|
|
136
142
|
ref: () => ({ timeline: { refetch: async () => {
|
|
137
143
|
entered(); await gate;
|
|
138
144
|
return { entries: [{ item: message, timestamp: earlier, seqStart: 1 }], hasOlder: false,
|
package/server/store.test.ts
CHANGED
|
@@ -148,6 +148,19 @@ test("sqlite: upsertAgents keeps earliest createdAt and sets archivedAt", () =>
|
|
|
148
148
|
assert.equal(agent?.archivedAt, "2026-09-20T00:00:00.000Z");
|
|
149
149
|
assert.equal(agent?.title, "One renamed");
|
|
150
150
|
assert.equal(store.selectAgents({ from: "2026-09-18T00:00:00.000Z" }).length, 1);
|
|
151
|
+
store.upsertAgents([
|
|
152
|
+
{
|
|
153
|
+
agentId: "a1",
|
|
154
|
+
workspaceId: "w1",
|
|
155
|
+
parentAgentId: null,
|
|
156
|
+
provider: "claude",
|
|
157
|
+
title: "One renamed",
|
|
158
|
+
createdAt: "2026-09-19T12:00:00.000Z",
|
|
159
|
+
archivedAt: null,
|
|
160
|
+
updatedAt: "2026-09-20T01:00:00.000Z",
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
assert.equal(store.getAgent("a1")?.archivedAt, null);
|
|
151
164
|
store.close();
|
|
152
165
|
});
|
|
153
166
|
|
package/server/store.ts
CHANGED
|
@@ -360,7 +360,7 @@ export function mergeAgentRow(previous: AgentRow, next: AgentRow): AgentRow {
|
|
|
360
360
|
provider: next.provider || previous.provider,
|
|
361
361
|
title: next.title ?? previous.title,
|
|
362
362
|
createdAt: previous.createdAt <= next.createdAt ? previous.createdAt : next.createdAt,
|
|
363
|
-
archivedAt: next.archivedAt
|
|
363
|
+
archivedAt: next.archivedAt,
|
|
364
364
|
updatedAt: next.updatedAt >= previous.updatedAt ? next.updatedAt : previous.updatedAt,
|
|
365
365
|
};
|
|
366
366
|
}
|
|
@@ -431,7 +431,7 @@ ON CONFLICT(agent_id) DO UPDATE SET
|
|
|
431
431
|
WHEN excluded.created_at < agents.created_at THEN excluded.created_at
|
|
432
432
|
ELSE agents.created_at
|
|
433
433
|
END,
|
|
434
|
-
archived_at =
|
|
434
|
+
archived_at = excluded.archived_at,
|
|
435
435
|
updated_at = excluded.updated_at
|
|
436
436
|
`;
|
|
437
437
|
|