@koinzhang/paseo-plugin-activity 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -1
- package/README.md +14 -7
- package/client/activity-heatmap.tsx +115 -74
- package/client/agent-creations.tsx +97 -88
- package/client/attention-pill.tsx +16 -5
- package/client/attention-popover.tsx +19 -23
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +168 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +236 -268
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +136 -103
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +83 -108
- package/client/provider-dropdown.tsx +131 -0
- package/client/provider-filter.test.ts +17 -13
- package/client/provider-filter.ts +5 -7
- package/client/rank-color.ts +3 -3
- package/client/ranking-bars.tsx +291 -0
- package/client/ui.tsx +339 -0
- package/client/usage-popover.tsx +62 -134
- package/client/usage-stats.tsx +29 -11
- package/client/use-agent-turn-end.ts +2 -1
- package/client/use-app-language.ts +17 -0
- package/client/web.ts +73 -18
- package/client/workspace/agent-row.tsx +18 -25
- package/client/workspace/agents-section.tsx +23 -20
- package/client/workspace/constants.ts +6 -6
- package/client/workspace/display-menu.tsx +5 -4
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +89 -103
- package/client/workspace/rank-section.tsx +36 -62
- package/client/workspace/terminals-section.tsx +13 -9
- package/index.client.tsx +40 -20
- package/index.server.ts +53 -51
- package/package.json +2 -2
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.ts +34 -4
- package/server/handlers-query.test.ts +27 -1
- package/server/handlers.ts +75 -31
- package/server/ingest.test.ts +8 -0
- package/server/messages.test.ts +96 -1
- package/server/prompt-dedupe.ts +52 -0
- package/server/rpc-cache.test.ts +74 -0
- package/server/rpc-cache.ts +48 -0
- package/server/store.test.ts +122 -0
- package/server/store.ts +313 -19
- package/server/ttl-cache.ts +3 -0
- package/shared/activity.test.ts +36 -0
- package/shared/activity.ts +37 -0
- package/shared/classify.test.ts +1 -10
- package/shared/classify.ts +3 -10
- package/shared/format.ts +10 -7
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +120 -81
- package/shared/insights.ts +124 -63
- package/shared/usage.test.ts +121 -0
- package/shared/usage.ts +191 -2
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
import { collapseHomePath } from "../../shared/home-path.ts";
|
|
15
15
|
import { TERMINAL_PREVIEW_LINES, TERMINAL_REFETCH_MS } from "./constants.ts";
|
|
16
16
|
import { terminalPreviewLines } from "./terminal-preview.ts";
|
|
17
|
+
import { CONTROL, ICON_SIZE } from "../design-tokens.ts";
|
|
18
|
+
import { useMessages } from "../use-app-language.ts";
|
|
17
19
|
|
|
18
20
|
export type TerminalListItem = {
|
|
19
21
|
id: string;
|
|
@@ -23,6 +25,7 @@ export type TerminalListItem = {
|
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type TerminalsSectionStyles = {
|
|
28
|
+
section: ViewStyle;
|
|
26
29
|
sectionHeaderRow: ViewStyle;
|
|
27
30
|
sectionTitle: TextStyle;
|
|
28
31
|
panel: ViewStyle;
|
|
@@ -52,6 +55,7 @@ export function TerminalsSection({
|
|
|
52
55
|
styles: TerminalsSectionStyles;
|
|
53
56
|
onClose: (item: TerminalListItem) => void;
|
|
54
57
|
}): ReactNode {
|
|
58
|
+
const m = useMessages();
|
|
55
59
|
const paseo = usePaseo();
|
|
56
60
|
const [expandedId, setExpandedId] = useState<string | null>(null);
|
|
57
61
|
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
|
@@ -76,9 +80,9 @@ export function TerminalsSection({
|
|
|
76
80
|
});
|
|
77
81
|
|
|
78
82
|
return (
|
|
79
|
-
<View style={
|
|
83
|
+
<View style={styles.section}>
|
|
80
84
|
<View style={styles.sectionHeaderRow}>
|
|
81
|
-
<Text style={styles.sectionTitle}>
|
|
85
|
+
<Text style={styles.sectionTitle}>{m.workspace.terminals}</Text>
|
|
82
86
|
</View>
|
|
83
87
|
<View style={styles.panel}>
|
|
84
88
|
{terminalItems.map((item) => {
|
|
@@ -92,7 +96,7 @@ export function TerminalsSection({
|
|
|
92
96
|
<Pressable
|
|
93
97
|
accessibilityRole="button"
|
|
94
98
|
accessibilityLabel={
|
|
95
|
-
expanded ?
|
|
99
|
+
expanded ? m.workspace.hideOutput(item.name) : m.workspace.showOutput(item.name)
|
|
96
100
|
}
|
|
97
101
|
accessibilityState={{ expanded }}
|
|
98
102
|
onPress={() => setExpandedId(expanded ? null : item.id)}
|
|
@@ -105,7 +109,7 @@ export function TerminalsSection({
|
|
|
105
109
|
} as object)
|
|
106
110
|
: null)}
|
|
107
111
|
>
|
|
108
|
-
<Icon name="Terminal" size={
|
|
112
|
+
<Icon name="Terminal" size={ICON_SIZE.leading} color={mutedColor} />
|
|
109
113
|
<View style={styles.listMain}>
|
|
110
114
|
<Text style={styles.listTitle} numberOfLines={1}>
|
|
111
115
|
{item.name}
|
|
@@ -116,10 +120,10 @@ export function TerminalsSection({
|
|
|
116
120
|
</View>
|
|
117
121
|
<Pressable
|
|
118
122
|
accessibilityRole="button"
|
|
119
|
-
accessibilityLabel={
|
|
123
|
+
accessibilityLabel={m.workspace.closeTerminal(item.name)}
|
|
120
124
|
accessibilityState={{ disabled: busyTerminalId != null }}
|
|
121
125
|
disabled={busyTerminalId != null || !showClose}
|
|
122
|
-
hitSlop={
|
|
126
|
+
hitSlop={CONTROL.hitSlop}
|
|
123
127
|
onPress={() => onClose(item)}
|
|
124
128
|
pointerEvents={showClose ? "auto" : "none"}
|
|
125
129
|
style={[styles.titleAction, { opacity: showClose ? 1 : 0 }]}
|
|
@@ -127,16 +131,16 @@ export function TerminalsSection({
|
|
|
127
131
|
{busy ? (
|
|
128
132
|
<ActivityIndicator size="small" color={mutedColor} />
|
|
129
133
|
) : (
|
|
130
|
-
<Icon name="X" size={
|
|
134
|
+
<Icon name="X" size={ICON_SIZE.inline} color={mutedColor} />
|
|
131
135
|
)}
|
|
132
136
|
</Pressable>
|
|
133
137
|
</Pressable>
|
|
134
138
|
{expanded ? (
|
|
135
139
|
<View style={styles.terminalPreview}>
|
|
136
140
|
{capture.isPending ? (
|
|
137
|
-
<Text style={styles.listMeta}>
|
|
141
|
+
<Text style={styles.listMeta}>{m.common.loading}</Text>
|
|
138
142
|
) : lines.length === 0 ? (
|
|
139
|
-
<Text style={styles.listMeta}>
|
|
143
|
+
<Text style={styles.listMeta}>{m.workspace.noOutput}</Text>
|
|
140
144
|
) : (
|
|
141
145
|
lines.map((line, index) => (
|
|
142
146
|
<Text key={index} style={styles.terminalLine} numberOfLines={1}>
|
package/index.client.tsx
CHANGED
|
@@ -2,11 +2,43 @@ import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
|
2
2
|
import { GlobalUsageSurface } from "./client/global-surface.tsx";
|
|
3
3
|
import { UsagePanel } from "./client/panel.tsx";
|
|
4
4
|
import { contributeAttentionPills } from "./client/attention-pill.tsx";
|
|
5
|
+
import { contributeHeaderButtons } from "./client/header-button.ts";
|
|
5
6
|
import { contributePills } from "./client/pill.tsx";
|
|
6
7
|
import { WorkspaceActivityPanel } from "./client/workspace-panel.tsx";
|
|
8
|
+
import { currentAppLanguage, watchAppLanguage } from "./client/use-app-language.ts";
|
|
9
|
+
import { messagesFor } from "./shared/i18n.ts";
|
|
7
10
|
|
|
8
11
|
const GLOBAL_SURFACE_ID = "activity";
|
|
9
12
|
|
|
13
|
+
/** Command titles follow the app language; the host has no update(), so re-register on change. */
|
|
14
|
+
function addScopedCommands(client: PluginClientContext): () => void {
|
|
15
|
+
const { commands } = messagesFor(currentAppLanguage());
|
|
16
|
+
const removeAgent = client.addCommandCenterItem({
|
|
17
|
+
id: "open-usage",
|
|
18
|
+
title: commands.agentActivity,
|
|
19
|
+
icon: "Activity",
|
|
20
|
+
keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
21
|
+
context: "agent",
|
|
22
|
+
onSelect: ({ openPanel }) => {
|
|
23
|
+
openPanel("usage");
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const removeWorkspace = client.addCommandCenterItem({
|
|
27
|
+
id: "open-workspace-activity",
|
|
28
|
+
title: commands.workspaceActivity,
|
|
29
|
+
icon: "Activity",
|
|
30
|
+
keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
31
|
+
context: "workspace",
|
|
32
|
+
onSelect({ openPanel }) {
|
|
33
|
+
openPanel("workspace-activity", { location: "explorer" });
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
removeAgent();
|
|
38
|
+
removeWorkspace();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
10
42
|
export default function contribute(client: PluginClientContext) {
|
|
11
43
|
client.addSurface(GLOBAL_SURFACE_ID, GlobalUsageSurface);
|
|
12
44
|
client.addSidebarItem({
|
|
@@ -44,32 +76,20 @@ export default function contribute(client: PluginClientContext) {
|
|
|
44
76
|
},
|
|
45
77
|
});
|
|
46
78
|
|
|
47
|
-
client
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
keywords: ["activity", "current", "agent", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
52
|
-
context: "agent",
|
|
53
|
-
onSelect: ({ openPanel }) => {
|
|
54
|
-
openPanel("usage");
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
client.addCommandCenterItem({
|
|
59
|
-
id: "open-workspace-activity",
|
|
60
|
-
title: "Workspace Activity",
|
|
61
|
-
icon: "Activity",
|
|
62
|
-
keywords: ["activity", "workspace", "explorer", "tool", "usage", "shell", "skill", "mcp", "stats"],
|
|
63
|
-
context: "workspace",
|
|
64
|
-
onSelect({ openPanel }) {
|
|
65
|
-
openPanel("workspace-activity", { location: "explorer" });
|
|
66
|
-
},
|
|
79
|
+
let removeScopedCommands = addScopedCommands(client);
|
|
80
|
+
const stopLanguage = watchAppLanguage(() => {
|
|
81
|
+
removeScopedCommands();
|
|
82
|
+
removeScopedCommands = addScopedCommands(client);
|
|
67
83
|
});
|
|
68
84
|
|
|
69
85
|
const stopUsagePills = contributePills(client);
|
|
70
86
|
const stopAttentionPills = contributeAttentionPills(client);
|
|
87
|
+
const stopHeaderButtons = contributeHeaderButtons(client);
|
|
71
88
|
return () => {
|
|
89
|
+
stopLanguage();
|
|
90
|
+
removeScopedCommands();
|
|
72
91
|
stopUsagePills();
|
|
73
92
|
stopAttentionPills();
|
|
93
|
+
stopHeaderButtons();
|
|
74
94
|
};
|
|
75
95
|
}
|
package/index.server.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createBackgroundSync } from "./server/background-sync.ts";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
3
|
+
import type { PluginHandlerContext, PluginServerContext } from "@getpaseo/plugin/server";
|
|
4
4
|
import {
|
|
5
5
|
createActivityByHourHandler,
|
|
6
6
|
createActivityByDayHandler,
|
|
7
7
|
createAgentCreationsHandler,
|
|
8
8
|
createAgentLifetimeHandler,
|
|
9
9
|
createAgentsHandler,
|
|
10
|
+
createByProjectHandler,
|
|
10
11
|
createByProviderHandler,
|
|
11
12
|
createExportHandler,
|
|
12
13
|
createListHandler,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
import { agentRowFromHook } from "./server/agents.ts";
|
|
22
23
|
import { ingestTimeline, ingestUserMessages } from "./server/ingest.ts";
|
|
23
24
|
import { resolveAgentModel } from "./server/resolve-model.ts";
|
|
25
|
+
import { createRpcCache } from "./server/rpc-cache.ts";
|
|
24
26
|
import { createUsageStore } from "./server/store.ts";
|
|
25
27
|
import {
|
|
26
28
|
usageActivityByHourRpc,
|
|
@@ -29,6 +31,7 @@ import {
|
|
|
29
31
|
usageAgentLifetimeRpc,
|
|
30
32
|
usageAgentsRpc,
|
|
31
33
|
usageAgentUnarchiveRpc,
|
|
34
|
+
usageByProjectRpc,
|
|
32
35
|
usageByProviderRpc,
|
|
33
36
|
usageExportRpc,
|
|
34
37
|
usageHostInfoRpc,
|
|
@@ -45,58 +48,51 @@ import { explorerAgentDisplaySettings } from "./shared/explorer-agent-display.ts
|
|
|
45
48
|
export default function contribute(server: PluginServerContext) {
|
|
46
49
|
const store = createUsageStore();
|
|
47
50
|
const background = createBackgroundSync(store);
|
|
51
|
+
const cache = createRpcCache({ generation: () => store.generation() });
|
|
48
52
|
console.log(`[activity] store ready (driver=${store.driver})`);
|
|
49
53
|
server.registerSettings(explorerAgentDisplaySettings);
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
server.handle(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
server.handle(usageByProviderRpc, (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
server.handle(usageAgentsRpc, (input, context) => {
|
|
80
|
-
void background.request(context.paseo);
|
|
81
|
-
return createAgentsHandler(store)(input);
|
|
82
|
-
});
|
|
55
|
+
/** Cached read RPC that also nudges the background history check. */
|
|
56
|
+
function read<I, O>(
|
|
57
|
+
rpc: { name: string },
|
|
58
|
+
handler: (input: I, context: PluginHandlerContext) => Promise<O>,
|
|
59
|
+
) {
|
|
60
|
+
const cached = cache.wrap(rpc.name, handler);
|
|
61
|
+
return (input: I, context: PluginHandlerContext) => {
|
|
62
|
+
void background.request(context.paseo);
|
|
63
|
+
return cached(input, context);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
server.handle(usageSummaryRpc, read(usageSummaryRpc, createSummaryHandler(store)));
|
|
68
|
+
server.handle(usageListRpc, read(usageListRpc, createListHandler(store)));
|
|
69
|
+
server.handle(usageSkillsByNameRpc, read(usageSkillsByNameRpc, createSkillsByNameHandler(store)));
|
|
70
|
+
server.handle(
|
|
71
|
+
usageRecentSkillCallsRpc,
|
|
72
|
+
read(usageRecentSkillCallsRpc, createRecentSkillCallsHandler(store)),
|
|
73
|
+
);
|
|
74
|
+
server.handle(
|
|
75
|
+
usageRecentMcpCallsRpc,
|
|
76
|
+
read(usageRecentMcpCallsRpc, createRecentMcpCallsHandler(store)),
|
|
77
|
+
);
|
|
78
|
+
server.handle(usageMcpByToolRpc, read(usageMcpByToolRpc, createMcpByToolHandler(store)));
|
|
79
|
+
server.handle(usageByProviderRpc, read(usageByProviderRpc, createByProviderHandler(store)));
|
|
80
|
+
server.handle(usageByProjectRpc, read(usageByProjectRpc, createByProjectHandler(store)));
|
|
81
|
+
server.handle(usageAgentsRpc, read(usageAgentsRpc, createAgentsHandler(store)));
|
|
83
82
|
server.handle(usageAgentUnarchiveRpc, createUnarchiveAgentHandler(store));
|
|
84
|
-
server.handle(usageActivityByDayRpc, (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
void background.request(context.paseo);
|
|
98
|
-
return createAgentCreationsHandler(store)(input);
|
|
99
|
-
});
|
|
83
|
+
server.handle(usageActivityByDayRpc, read(usageActivityByDayRpc, createActivityByDayHandler(store)));
|
|
84
|
+
server.handle(
|
|
85
|
+
usageActivityByHourRpc,
|
|
86
|
+
read(usageActivityByHourRpc, createActivityByHourHandler(store)),
|
|
87
|
+
);
|
|
88
|
+
server.handle(
|
|
89
|
+
usageAgentLifetimeRpc,
|
|
90
|
+
read(usageAgentLifetimeRpc, createAgentLifetimeHandler(store)),
|
|
91
|
+
);
|
|
92
|
+
server.handle(
|
|
93
|
+
usageAgentCreationsRpc,
|
|
94
|
+
read(usageAgentCreationsRpc, createAgentCreationsHandler(store)),
|
|
95
|
+
);
|
|
100
96
|
server.handle(usageExportRpc, createExportHandler(store));
|
|
101
97
|
server.handle(usageHostInfoRpc, () => ({ homeDir: homedir() }));
|
|
102
98
|
server.handle(usageReadSkillRpc, createReadSkillHandler());
|
|
@@ -141,8 +137,14 @@ export default function contribute(server: PluginServerContext) {
|
|
|
141
137
|
store.upsertUserMessages(
|
|
142
138
|
ingestUserMessages(event.timeline, event.agent, { model }),
|
|
143
139
|
);
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
store.pruneReplayDuplicateMessages(event.agent.id);
|
|
141
|
+
// event.timeline is the whole history; calls already stored in a terminal
|
|
142
|
+
// status cannot change from a live snapshot, so only the rest are upserted.
|
|
143
|
+
const settled = store.terminalCallIds(event.agent.id);
|
|
144
|
+
const pending = event.timeline.filter(
|
|
145
|
+
(item) => item.type !== "tool_call" || !settled.has(item.callId),
|
|
146
|
+
);
|
|
147
|
+
const rows = ingestTimeline(pending, event.agent, null, {
|
|
146
148
|
homeDir: homedir(),
|
|
147
149
|
});
|
|
148
150
|
if (rows.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koinzhang/paseo-plugin-activity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Local usage analytics and workspace agent ops for Paseo: tools, agents, messages, models, Explorer fleet list, and terminals.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
|
-
"test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/agent-directory.test.ts client/workspace/list-host-agents.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/color-mix.test.ts client/fit-text.test.ts client/provider-filter.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/explorer-agent-display.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"
|
|
25
|
+
"test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/agent-directory.test.ts client/workspace/list-host-agents.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/color-mix.test.ts client/design-tokens.test.ts client/fit-text.test.ts client/provider-filter.test.ts client/range.test.ts client/panel-visibility.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/i18n.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/explorer-agent-display.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 server/rpc-cache.test.ts"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@getpaseo/plugin": "0.9.0-beta.2",
|
package/paseo-plugin.json
CHANGED
package/server/agents.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PluginHookAgent } from "@getpaseo/plugin/server";
|
|
2
|
-
import type { AgentRow, ToolCallRow } from "./store.ts";
|
|
2
|
+
import type { AgentActivitySpan, AgentRow, ToolCallRow } from "./store.ts";
|
|
3
3
|
|
|
4
4
|
function nowIso(): string {
|
|
5
5
|
return new Date().toISOString();
|
|
@@ -19,6 +19,7 @@ export function agentRowFromHook(
|
|
|
19
19
|
createdAt: opts.createdAt ?? updatedAt,
|
|
20
20
|
archivedAt: opts.archivedAt ?? null,
|
|
21
21
|
updatedAt,
|
|
22
|
+
cwd: agent.cwd || null,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -31,7 +32,8 @@ export function agentRowFromSnapshot(agent: {
|
|
|
31
32
|
createdAt: string;
|
|
32
33
|
updatedAt?: string;
|
|
33
34
|
archivedAt?: string | null;
|
|
34
|
-
|
|
35
|
+
cwd?: string | null;
|
|
36
|
+
}, projectRoot?: string | null): AgentRow {
|
|
35
37
|
const updatedAt = agent.updatedAt ?? agent.createdAt;
|
|
36
38
|
return {
|
|
37
39
|
agentId: agent.id,
|
|
@@ -42,9 +44,25 @@ export function agentRowFromSnapshot(agent: {
|
|
|
42
44
|
createdAt: agent.createdAt,
|
|
43
45
|
archivedAt: agent.archivedAt ?? null,
|
|
44
46
|
updatedAt,
|
|
47
|
+
cwd: agent.cwd || null,
|
|
48
|
+
projectRoot: projectRoot ?? null,
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
/** Store-aggregated activity spans → registry rows (same shape as `agentsFromToolCalls`). */
|
|
53
|
+
export function agentsFromActivitySpans(spans: readonly AgentActivitySpan[]): AgentRow[] {
|
|
54
|
+
return spans.map((span) => ({
|
|
55
|
+
agentId: span.agentId,
|
|
56
|
+
workspaceId: span.workspaceId,
|
|
57
|
+
parentAgentId: null,
|
|
58
|
+
provider: span.provider,
|
|
59
|
+
title: null,
|
|
60
|
+
createdAt: span.firstAt,
|
|
61
|
+
archivedAt: null,
|
|
62
|
+
updatedAt: span.lastAt,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
|
|
48
66
|
/** Earliest tool activity per agentId → approximate created_at for unknown agents. */
|
|
49
67
|
export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
|
|
50
68
|
const earliest = new Map<
|
|
@@ -5,7 +5,7 @@ import { LOG_PREFIX } from "../shared/plugin-id.ts";
|
|
|
5
5
|
import { listAllAgentPages } from "../shared/list-agent-pages.ts";
|
|
6
6
|
import type { UsageStore } from "./store.ts";
|
|
7
7
|
import { defaultDataDir } from "./store.ts";
|
|
8
|
-
import { agentRowFromSnapshot,
|
|
8
|
+
import { agentRowFromSnapshot, agentsFromActivitySpans } from "./agents.ts";
|
|
9
9
|
import { resyncAgents } from "./handlers.ts";
|
|
10
10
|
|
|
11
11
|
type PaseoApi = PluginHandlerContext["paseo"];
|
|
@@ -27,6 +27,21 @@ async function listAllAgents(paseo: PaseoApi) {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** Active workspace id → project root; archived workspaces are not listed (070). */
|
|
31
|
+
async function listWorkspaceProjectRoots(paseo: PaseoApi): Promise<Map<string, string>> {
|
|
32
|
+
const roots = new Map<string, string>();
|
|
33
|
+
let cursor: string | undefined;
|
|
34
|
+
for (let pages = 0; pages < 100; pages++) {
|
|
35
|
+
const page = await paseo.workspaces.list({
|
|
36
|
+
page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
37
|
+
});
|
|
38
|
+
for (const workspace of page.entries) roots.set(workspace.id, workspace.projectRootPath);
|
|
39
|
+
if (!page.pageInfo.hasMore || !page.pageInfo.nextCursor) break;
|
|
40
|
+
cursor = page.pageInfo.nextCursor;
|
|
41
|
+
}
|
|
42
|
+
return roots;
|
|
43
|
+
}
|
|
44
|
+
|
|
30
45
|
export function createBackgroundSync(store: UsageStore, options: {
|
|
31
46
|
path?: string;
|
|
32
47
|
version?: number;
|
|
@@ -60,11 +75,21 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
60
75
|
|
|
61
76
|
async function check(paseo: PaseoApi) {
|
|
62
77
|
const listedEntries = await listAllAgents(paseo);
|
|
78
|
+
const projectRoots = await listWorkspaceProjectRoots(paseo).catch((error) => {
|
|
79
|
+
console.error("[activity] workspace project roots unavailable", error);
|
|
80
|
+
return new Map<string, string>();
|
|
81
|
+
});
|
|
63
82
|
if (controller.signal.aborted) return;
|
|
64
83
|
// Directory synchronization belongs to the background task, never a UI read.
|
|
65
|
-
store.upsertAgents(
|
|
84
|
+
store.upsertAgents(
|
|
85
|
+
listedEntries.map(({ agent }) =>
|
|
86
|
+
agentRowFromSnapshot(agent, agent.workspaceId ? projectRoots.get(agent.workspaceId) : null),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
66
89
|
const known = new Set(store.selectAgents().map(agent => agent.agentId));
|
|
67
|
-
store.upsertAgents(
|
|
90
|
+
store.upsertAgents(
|
|
91
|
+
agentsFromActivitySpans(store.agentActivitySpans()).filter(agent => !known.has(agent.agentId)),
|
|
92
|
+
);
|
|
68
93
|
console.log(
|
|
69
94
|
`${LOG_PREFIX} directory sync listed=${listedEntries.length} (archived=${listedEntries.filter(entry => entry.agent.archivedAt).length}) registry=${known.size}`,
|
|
70
95
|
);
|
|
@@ -85,7 +110,12 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
85
110
|
if (agent.archivedAt) continue;
|
|
86
111
|
const stamp = `${agent.updatedAt}:${agent.lastUserMessageAt ?? ""}`;
|
|
87
112
|
if (checkpoints[agent.id] === stamp) continue;
|
|
88
|
-
|
|
113
|
+
// A checkpoint under this BACKFILL_VERSION means earlier rows already carry
|
|
114
|
+
// current classification, so only the new timeline tail needs scanning.
|
|
115
|
+
const incremental = checkpoints[agent.id] !== undefined;
|
|
116
|
+
const result = await scan(store, paseo, [agent.id], controller.signal, listedEntries, {
|
|
117
|
+
incremental,
|
|
118
|
+
});
|
|
89
119
|
if (controller.signal.aborted) return;
|
|
90
120
|
if (result.errors.length || result.syncedAgents !== 1) {
|
|
91
121
|
console.error("[activity] background history scan incomplete", agent.id, result.errors);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
createAgentsHandler,
|
|
13
13
|
createByProviderHandler,
|
|
14
14
|
createRecentMcpCallsHandler,
|
|
15
|
+
createReadSkillHandler,
|
|
15
16
|
createRecentSkillCallsHandler,
|
|
16
17
|
createSkillsByNameHandler,
|
|
17
18
|
} from "./handlers.ts";
|
|
@@ -393,3 +394,28 @@ test("skills-by-name keeps counts when agent metadata is unavailable", async ()
|
|
|
393
394
|
rmSync(dir, { recursive: true, force: true });
|
|
394
395
|
}
|
|
395
396
|
});
|
|
397
|
+
|
|
398
|
+
test("read-skill rejects SKILL.md symlinks to other files but follows symlinked skill dirs (064)", async () => {
|
|
399
|
+
const home = mkdtempSync(join(tmpdir(), "activity-read-skill-"));
|
|
400
|
+
const previousHome = process.env.HOME;
|
|
401
|
+
process.env.HOME = home;
|
|
402
|
+
try {
|
|
403
|
+
const skills = join(home, ".claude", "skills");
|
|
404
|
+
mkdirSync(join(skills, "evil"), { recursive: true });
|
|
405
|
+
writeFileSync(join(home, "secret.txt"), "private key");
|
|
406
|
+
symlinkSync(join(home, "secret.txt"), join(skills, "evil", "SKILL.md"));
|
|
407
|
+
const external = join(home, "dotfiles", "good");
|
|
408
|
+
mkdirSync(external, { recursive: true });
|
|
409
|
+
writeFileSync(join(external, "SKILL.md"), "# good");
|
|
410
|
+
symlinkSync(external, join(skills, "good"));
|
|
411
|
+
|
|
412
|
+
const read = createReadSkillHandler();
|
|
413
|
+
await assert.rejects(read({ path: "~/.claude/skills/evil/SKILL.md" }), /not allowed/);
|
|
414
|
+
const ok = await read({ path: "~/.claude/skills/good/SKILL.md" });
|
|
415
|
+
assert.equal(ok.body, "# good");
|
|
416
|
+
assert.equal(ok.path, "~/.claude/skills/good/SKILL.md");
|
|
417
|
+
} finally {
|
|
418
|
+
process.env.HOME = previousHome;
|
|
419
|
+
rmSync(home, { recursive: true, force: true });
|
|
420
|
+
}
|
|
421
|
+
});
|