@koinzhang/paseo-plugin-activity 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -1
- package/README.md +15 -8
- package/client/activity-heatmap.tsx +126 -93
- package/client/agent-creations.tsx +216 -0
- package/client/attention-pill.tsx +16 -5
- package/client/attention-popover.tsx +19 -23
- package/client/color-mix.test.ts +27 -0
- package/client/color-mix.ts +38 -0
- package/client/design-tokens.test.ts +39 -0
- package/client/design-tokens.ts +168 -0
- package/client/fit-text.test.ts +41 -0
- package/client/fit-text.ts +33 -0
- package/client/formatted-time.tsx +4 -4
- package/client/global-surface.tsx +316 -275
- package/client/header-button.ts +136 -0
- package/client/hourly-activity-timeline.tsx +425 -0
- package/client/measured-width.ts +72 -0
- package/client/panel-visibility.test.ts +25 -0
- package/client/panel-visibility.ts +45 -0
- package/client/panel.tsx +83 -108
- package/client/provider-dropdown.tsx +131 -0
- package/client/provider-filter.test.ts +17 -13
- package/client/provider-filter.ts +5 -7
- package/client/range.test.ts +44 -0
- package/client/range.ts +14 -0
- package/client/rank-color.test.ts +108 -14
- package/client/rank-color.ts +261 -48
- package/client/ranking-bars.tsx +291 -0
- package/client/ui.tsx +339 -0
- package/client/usage-popover.tsx +62 -134
- package/client/usage-stats.tsx +137 -8
- package/client/use-agent-turn-end.ts +2 -1
- package/client/use-app-language.ts +17 -0
- package/client/web.ts +73 -18
- package/client/workspace/agent-row.tsx +18 -25
- package/client/workspace/agents-section.tsx +23 -20
- package/client/workspace/constants.ts +6 -6
- package/client/workspace/display-menu.tsx +5 -4
- package/client/workspace/filters.test.ts +1 -1
- package/client/workspace/filters.ts +4 -2
- package/client/workspace/panel.tsx +176 -104
- package/client/workspace/rank-section.tsx +157 -44
- package/client/workspace/terminals-section.tsx +13 -9
- package/index.client.tsx +40 -20
- package/index.server.ts +63 -31
- package/package.json +2 -2
- package/paseo-plugin.json +2 -1
- package/server/agents.ts +20 -2
- package/server/background-sync.test.ts +43 -0
- package/server/background-sync.ts +43 -4
- package/server/handlers-query.test.ts +252 -1
- package/server/handlers.ts +174 -13
- package/server/ingest.test.ts +8 -0
- package/server/messages.test.ts +96 -1
- package/server/prompt-dedupe.ts +52 -0
- package/server/rpc-cache.test.ts +74 -0
- package/server/rpc-cache.ts +48 -0
- package/server/store.test.ts +122 -0
- package/server/store.ts +313 -19
- package/server/ttl-cache.ts +3 -0
- package/shared/activity.test.ts +159 -6
- package/shared/activity.ts +140 -5
- package/shared/classify.test.ts +1 -0
- package/shared/classify.ts +4 -1
- package/shared/explorer-agent-display.test.ts +61 -0
- package/shared/explorer-agent-display.ts +21 -2
- package/shared/format.test.ts +28 -3
- package/shared/format.ts +25 -2
- package/shared/i18n.test.ts +34 -0
- package/shared/i18n.ts +363 -0
- package/shared/insights.test.ts +162 -80
- package/shared/insights.ts +136 -61
- package/shared/usage.test.ts +330 -0
- package/shared/usage.ts +471 -0
package/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<
|
|
@@ -152,3 +152,46 @@ test("stopping after agents.list prevents directory writes", async () => {
|
|
|
152
152
|
f.cleanup();
|
|
153
153
|
}
|
|
154
154
|
});
|
|
155
|
+
|
|
156
|
+
test("archived agents are registered but never scanned", async () => {
|
|
157
|
+
const f = fixture();
|
|
158
|
+
const archived = {
|
|
159
|
+
id: "archived-1",
|
|
160
|
+
provider: "codex",
|
|
161
|
+
createdAt: "2026-09-07T03:34:09.656Z",
|
|
162
|
+
updatedAt: "2026-09-07T03:34:09.656Z",
|
|
163
|
+
lastUserMessageAt: null,
|
|
164
|
+
archivedAt: "2026-09-18T17:18:18.001Z",
|
|
165
|
+
};
|
|
166
|
+
const listOptions: Array<Record<string, unknown>> = [];
|
|
167
|
+
const paseo = {
|
|
168
|
+
agents: {
|
|
169
|
+
list: async (options: Record<string, unknown>) => {
|
|
170
|
+
listOptions.push(options);
|
|
171
|
+
return {
|
|
172
|
+
entries: [{ agent: f.agent }, { agent: archived }],
|
|
173
|
+
pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
} as unknown as PaseoApi;
|
|
178
|
+
let scans = 0;
|
|
179
|
+
const sync = createBackgroundSync(f.store, {
|
|
180
|
+
path: f.path,
|
|
181
|
+
scan: async () => {
|
|
182
|
+
scans++;
|
|
183
|
+
return { syncedAgents: 1, inserted: 0, errors: [] };
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
try {
|
|
187
|
+
await sync.request(paseo);
|
|
188
|
+
assert.equal(scans, 1);
|
|
189
|
+
assert.deepEqual(listOptions[0]?.filter, { includeArchived: true });
|
|
190
|
+
const row = f.store.getAgent("archived-1");
|
|
191
|
+
assert.equal(row?.createdAt, "2026-09-07T03:34:09.656Z");
|
|
192
|
+
assert.equal(row?.archivedAt, "2026-09-18T17:18:18.001Z");
|
|
193
|
+
} finally {
|
|
194
|
+
sync.stop();
|
|
195
|
+
f.cleanup();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
@@ -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"];
|
|
@@ -18,12 +18,30 @@ const AGENT_LIST_PAGE_LIMIT = 200;
|
|
|
18
18
|
async function listAllAgents(paseo: PaseoApi) {
|
|
19
19
|
return listAllAgentPages(async (cursor) => {
|
|
20
20
|
const result = await paseo.agents.list({
|
|
21
|
+
// Archived agents only appear with this filter (049): without it their
|
|
22
|
+
// createdAt / archivedAt never reach the local registry.
|
|
23
|
+
filter: { includeArchived: true },
|
|
21
24
|
page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
22
25
|
});
|
|
23
26
|
return { entries: result.entries, pageInfo: result.pageInfo };
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
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
|
+
|
|
27
45
|
export function createBackgroundSync(store: UsageStore, options: {
|
|
28
46
|
path?: string;
|
|
29
47
|
version?: number;
|
|
@@ -57,11 +75,24 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
57
75
|
|
|
58
76
|
async function check(paseo: PaseoApi) {
|
|
59
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
|
+
});
|
|
60
82
|
if (controller.signal.aborted) return;
|
|
61
83
|
// Directory synchronization belongs to the background task, never a UI read.
|
|
62
|
-
store.upsertAgents(
|
|
84
|
+
store.upsertAgents(
|
|
85
|
+
listedEntries.map(({ agent }) =>
|
|
86
|
+
agentRowFromSnapshot(agent, agent.workspaceId ? projectRoots.get(agent.workspaceId) : null),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
63
89
|
const known = new Set(store.selectAgents().map(agent => agent.agentId));
|
|
64
|
-
store.upsertAgents(
|
|
90
|
+
store.upsertAgents(
|
|
91
|
+
agentsFromActivitySpans(store.agentActivitySpans()).filter(agent => !known.has(agent.agentId)),
|
|
92
|
+
);
|
|
93
|
+
console.log(
|
|
94
|
+
`${LOG_PREFIX} directory sync listed=${listedEntries.length} (archived=${listedEntries.filter(entry => entry.agent.archivedAt).length}) registry=${known.size}`,
|
|
95
|
+
);
|
|
65
96
|
|
|
66
97
|
const liveIds = new Set(listedEntries.map(({ agent }) => agent.id));
|
|
67
98
|
const pruned: Record<string, string> = Object.create(null);
|
|
@@ -74,9 +105,17 @@ export function createBackgroundSync(store: UsageStore, options: {
|
|
|
74
105
|
|
|
75
106
|
for (const { agent } of listedEntries) {
|
|
76
107
|
if (controller.signal.aborted) return;
|
|
108
|
+
// Archived agents contribute registry metadata only: their timeline is
|
|
109
|
+
// frozen and a full scan per agent would dwarf the 5-minute budget.
|
|
110
|
+
if (agent.archivedAt) continue;
|
|
77
111
|
const stamp = `${agent.updatedAt}:${agent.lastUserMessageAt ?? ""}`;
|
|
78
112
|
if (checkpoints[agent.id] === stamp) continue;
|
|
79
|
-
|
|
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
|
+
});
|
|
80
119
|
if (controller.signal.aborted) return;
|
|
81
120
|
if (result.errors.length || result.syncedAgents !== 1) {
|
|
82
121
|
console.error("[activity] background history scan incomplete", agent.id, result.errors);
|
|
@@ -1,13 +1,19 @@
|
|
|
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";
|
|
6
6
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
7
7
|
import {
|
|
8
|
+
createActivityByHourHandler,
|
|
8
9
|
createActivityByDayHandler,
|
|
10
|
+
createAgentCreationsHandler,
|
|
11
|
+
createAgentLifetimeHandler,
|
|
9
12
|
createAgentsHandler,
|
|
10
13
|
createByProviderHandler,
|
|
14
|
+
createRecentMcpCallsHandler,
|
|
15
|
+
createReadSkillHandler,
|
|
16
|
+
createRecentSkillCallsHandler,
|
|
11
17
|
createSkillsByNameHandler,
|
|
12
18
|
} from "./handlers.ts";
|
|
13
19
|
import { createUsageStore, type ToolCallRow } from "./store.ts";
|
|
@@ -60,6 +66,15 @@ test("by-provider and activity-by-day read the local store only", async () => {
|
|
|
60
66
|
const activity = await createActivityByDayHandler(store)({});
|
|
61
67
|
assert.equal(activity.days[0]?.skills, 1);
|
|
62
68
|
assert.equal(activity.days[0]?.agents, 1);
|
|
69
|
+
const hourly = await createActivityByHourHandler(
|
|
70
|
+
store,
|
|
71
|
+
() => new Date("2026-09-19T12:30:00.000Z"),
|
|
72
|
+
)({ hours: 2 });
|
|
73
|
+
assert.equal(hourly.hours.length, 2);
|
|
74
|
+
assert.equal(hourly.hours[0]?.start, "2026-09-19T11:00:00.000Z");
|
|
75
|
+
assert.equal(hourly.hours[0]?.total, 0);
|
|
76
|
+
assert.equal(hourly.hours[1]?.skills, 1);
|
|
77
|
+
assert.equal(hourly.hours[1]?.agents, 1);
|
|
63
78
|
} finally {
|
|
64
79
|
store.close();
|
|
65
80
|
rmSync(dir, { recursive: true, force: true });
|
|
@@ -123,6 +138,217 @@ test("usage.agents filters by workspace and merges the registry", async () => {
|
|
|
123
138
|
}
|
|
124
139
|
});
|
|
125
140
|
|
|
141
|
+
test("recent skill calls returns newest workspace calls with agent titles", async () => {
|
|
142
|
+
const dir = mkdtempSync(join(tmpdir(), "recent-skills-"));
|
|
143
|
+
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
144
|
+
try {
|
|
145
|
+
store.upsertMany([
|
|
146
|
+
row({ agentId: "a1", callId: "older", skillName: "review", ts: "2026-09-19T10:00:00.000Z" }),
|
|
147
|
+
row({ agentId: "a2", callId: "newer", skillName: "paseo", ts: "2026-09-19T12:00:00.000Z" }),
|
|
148
|
+
row({
|
|
149
|
+
agentId: "a1",
|
|
150
|
+
callId: "low",
|
|
151
|
+
skillName: "reference-only",
|
|
152
|
+
confidence: "low",
|
|
153
|
+
ts: "2026-09-19T13:00:00.000Z",
|
|
154
|
+
}),
|
|
155
|
+
row({
|
|
156
|
+
agentId: "other",
|
|
157
|
+
callId: "other-workspace",
|
|
158
|
+
workspaceId: "w2",
|
|
159
|
+
ts: "2026-09-19T14:00:00.000Z",
|
|
160
|
+
}),
|
|
161
|
+
]);
|
|
162
|
+
store.upsertAgents([
|
|
163
|
+
{
|
|
164
|
+
agentId: "a1",
|
|
165
|
+
workspaceId: "w1",
|
|
166
|
+
parentAgentId: null,
|
|
167
|
+
provider: "codex",
|
|
168
|
+
title: "Alpha",
|
|
169
|
+
createdAt: "2026-09-19T09:00:00.000Z",
|
|
170
|
+
archivedAt: null,
|
|
171
|
+
updatedAt: "2026-09-19T10:00:00.000Z",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
agentId: "a2",
|
|
175
|
+
workspaceId: "w1",
|
|
176
|
+
parentAgentId: null,
|
|
177
|
+
provider: "codex",
|
|
178
|
+
title: null,
|
|
179
|
+
createdAt: "2026-09-19T09:00:00.000Z",
|
|
180
|
+
archivedAt: null,
|
|
181
|
+
updatedAt: "2026-09-19T12:00:00.000Z",
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
const result = await createRecentSkillCallsHandler(store)({
|
|
186
|
+
workspaceId: "w1",
|
|
187
|
+
limit: 2,
|
|
188
|
+
});
|
|
189
|
+
assert.deepEqual(
|
|
190
|
+
result.items.map((item) => [
|
|
191
|
+
item.callId,
|
|
192
|
+
item.skillName,
|
|
193
|
+
item.agentTitle,
|
|
194
|
+
item.calledAt,
|
|
195
|
+
]),
|
|
196
|
+
[
|
|
197
|
+
["newer", "paseo", null, "2026-09-19T12:00:00.000Z"],
|
|
198
|
+
["older", "review", "Alpha", "2026-09-19T10:00:00.000Z"],
|
|
199
|
+
],
|
|
200
|
+
);
|
|
201
|
+
} finally {
|
|
202
|
+
store.close();
|
|
203
|
+
rmSync(dir, { recursive: true, force: true });
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("recent MCP calls returns newest workspace calls with agent titles", async () => {
|
|
208
|
+
const dir = mkdtempSync(join(tmpdir(), "recent-mcp-"));
|
|
209
|
+
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
210
|
+
try {
|
|
211
|
+
store.upsertMany([
|
|
212
|
+
row({
|
|
213
|
+
agentId: "a1",
|
|
214
|
+
callId: "older",
|
|
215
|
+
category: "mcp",
|
|
216
|
+
skillName: null,
|
|
217
|
+
mcpServer: "github",
|
|
218
|
+
mcpTool: "search",
|
|
219
|
+
ts: "2026-09-19T10:00:00.000Z",
|
|
220
|
+
}),
|
|
221
|
+
row({
|
|
222
|
+
agentId: "a2",
|
|
223
|
+
callId: "newer",
|
|
224
|
+
category: "mcp",
|
|
225
|
+
skillName: null,
|
|
226
|
+
mcpServer: "paseo",
|
|
227
|
+
mcpTool: "list_agents",
|
|
228
|
+
ts: "2026-09-19T12:00:00.000Z",
|
|
229
|
+
}),
|
|
230
|
+
row({
|
|
231
|
+
agentId: "other",
|
|
232
|
+
callId: "other-workspace",
|
|
233
|
+
workspaceId: "w2",
|
|
234
|
+
category: "mcp",
|
|
235
|
+
skillName: null,
|
|
236
|
+
mcpServer: "other",
|
|
237
|
+
mcpTool: "tool",
|
|
238
|
+
ts: "2026-09-19T14:00:00.000Z",
|
|
239
|
+
}),
|
|
240
|
+
]);
|
|
241
|
+
store.upsertAgents([
|
|
242
|
+
{
|
|
243
|
+
agentId: "a1",
|
|
244
|
+
workspaceId: "w1",
|
|
245
|
+
parentAgentId: null,
|
|
246
|
+
provider: "codex",
|
|
247
|
+
title: "Alpha",
|
|
248
|
+
createdAt: "2026-09-19T09:00:00.000Z",
|
|
249
|
+
archivedAt: null,
|
|
250
|
+
updatedAt: "2026-09-19T10:00:00.000Z",
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
|
|
254
|
+
const result = await createRecentMcpCallsHandler(store)({
|
|
255
|
+
workspaceId: "w1",
|
|
256
|
+
limit: 2,
|
|
257
|
+
});
|
|
258
|
+
assert.deepEqual(
|
|
259
|
+
result.items.map((item) => [
|
|
260
|
+
item.callId,
|
|
261
|
+
`${item.server}.${item.tool}`,
|
|
262
|
+
item.agentTitle,
|
|
263
|
+
]),
|
|
264
|
+
[
|
|
265
|
+
["newer", "paseo.list_agents", null],
|
|
266
|
+
["older", "github.search", "Alpha"],
|
|
267
|
+
],
|
|
268
|
+
);
|
|
269
|
+
} finally {
|
|
270
|
+
store.close();
|
|
271
|
+
rmSync(dir, { recursive: true, force: true });
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("usage.agent-lifetime reads spans from the registry, active agents included", async () => {
|
|
276
|
+
const dir = mkdtempSync(join(tmpdir(), "fast-lifetime-"));
|
|
277
|
+
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
278
|
+
const registryRow = (
|
|
279
|
+
agentId: string,
|
|
280
|
+
provider: string,
|
|
281
|
+
createdAt: string,
|
|
282
|
+
archivedAt: string | null,
|
|
283
|
+
) => ({
|
|
284
|
+
agentId,
|
|
285
|
+
workspaceId: "w1",
|
|
286
|
+
parentAgentId: null,
|
|
287
|
+
provider,
|
|
288
|
+
title: agentId,
|
|
289
|
+
createdAt,
|
|
290
|
+
archivedAt,
|
|
291
|
+
updatedAt: archivedAt ?? createdAt,
|
|
292
|
+
});
|
|
293
|
+
try {
|
|
294
|
+
store.upsertAgents([
|
|
295
|
+
registryRow("codex-old", "codex", "2026-09-07T03:34:09.656Z", "2026-09-18T17:18:18.001Z"),
|
|
296
|
+
registryRow("claude-long", "claude", "2026-09-08T03:09:29.070Z", "2026-09-19T17:18:17.939Z"),
|
|
297
|
+
registryRow("active", "claude", "2026-09-01T00:00:00.000Z", null),
|
|
298
|
+
]);
|
|
299
|
+
const all = await createAgentLifetimeHandler(store)({});
|
|
300
|
+
// `active` spans created→now, which is wider than either archived span.
|
|
301
|
+
assert.equal(all.longest?.agentId, "active");
|
|
302
|
+
assert.equal(all.longest?.archivedAt, null);
|
|
303
|
+
assert.equal(all.sampleSize, 3);
|
|
304
|
+
|
|
305
|
+
const codexOnly = await createAgentLifetimeHandler(store)({ provider: "codex" });
|
|
306
|
+
assert.equal(codexOnly.longest?.agentId, "codex-old");
|
|
307
|
+
assert.equal(codexOnly.sampleSize, 1);
|
|
308
|
+
} finally {
|
|
309
|
+
store.close();
|
|
310
|
+
rmSync(dir, { recursive: true, force: true });
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("usage.agent-creations buckets registry rows by day and provider", async () => {
|
|
315
|
+
const dir = mkdtempSync(join(tmpdir(), "fast-creations-"));
|
|
316
|
+
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
317
|
+
try {
|
|
318
|
+
store.upsertAgents(
|
|
319
|
+
[
|
|
320
|
+
["a1", "claude-code", "2026-09-19T01:00:00.000Z"],
|
|
321
|
+
["a2", "claude", "2026-09-19T02:00:00.000Z"],
|
|
322
|
+
["a3", "codex", "2026-09-19T03:00:00.000Z"],
|
|
323
|
+
["a4", "codex", "2026-08-01T03:00:00.000Z"],
|
|
324
|
+
].map(([agentId, provider, createdAt]) => ({
|
|
325
|
+
agentId: agentId!,
|
|
326
|
+
workspaceId: "w1",
|
|
327
|
+
parentAgentId: null,
|
|
328
|
+
provider: provider!,
|
|
329
|
+
title: agentId!,
|
|
330
|
+
createdAt: createdAt!,
|
|
331
|
+
archivedAt: null,
|
|
332
|
+
updatedAt: createdAt!,
|
|
333
|
+
})),
|
|
334
|
+
);
|
|
335
|
+
const all = await createAgentCreationsHandler(store)({ from: "2026-09-01T00:00:00.000Z" });
|
|
336
|
+
assert.deepEqual(
|
|
337
|
+
all.days.map((day) => [day.date, day.total, day.providers.map((item) => `${item.provider}:${item.count}`)]),
|
|
338
|
+
[["2026-09-19", 3, ["claude:2", "codex:1"]]],
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
const codexOnly = await createAgentCreationsHandler(store)({ provider: "codex" });
|
|
342
|
+
assert.deepEqual(codexOnly.days.map((day) => [day.date, day.total]), [
|
|
343
|
+
["2026-08-01", 1],
|
|
344
|
+
["2026-09-19", 1],
|
|
345
|
+
]);
|
|
346
|
+
} finally {
|
|
347
|
+
store.close();
|
|
348
|
+
rmSync(dir, { recursive: true, force: true });
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
126
352
|
test("skills-by-name refreshes an empty handle and resolves project skills", async () => {
|
|
127
353
|
const dir = mkdtempSync(join(tmpdir(), "fast-skills-"));
|
|
128
354
|
const store = createUsageStore({ dir, driver: "sqlite" });
|
|
@@ -168,3 +394,28 @@ test("skills-by-name keeps counts when agent metadata is unavailable", async ()
|
|
|
168
394
|
rmSync(dir, { recursive: true, force: true });
|
|
169
395
|
}
|
|
170
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
|
+
});
|