@koinzhang/paseo-plugin-activity 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/README.md +71 -0
- package/client/activity-heatmap.tsx +72 -14
- package/client/global-surface.tsx +24 -25
- package/client/panel.tsx +1 -0
- package/client/range.ts +20 -0
- package/client/usage-stats.tsx +7 -5
- package/client/workspace/agent-row.tsx +117 -0
- package/client/workspace/agents-section.tsx +323 -0
- package/client/workspace/constants.ts +121 -0
- package/client/workspace/display-menu.tsx +116 -0
- package/client/workspace/filters.ts +30 -0
- package/client/workspace/list-host-agents.ts +57 -0
- package/client/workspace/panel.tsx +800 -0
- package/client/workspace/rank-section.tsx +121 -0
- package/client/workspace-panel.tsx +2 -0
- package/index.client.tsx +20 -13
- package/index.server.ts +11 -0
- package/package.json +8 -2
- package/server/agents.test.ts +20 -1
- package/server/agents.ts +2 -1
- package/server/background-sync.test.ts +14 -3
- package/server/background-sync.ts +16 -5
- package/server/handlers-query.test.ts +58 -0
- package/server/handlers.ts +73 -2
- package/server/messages.test.ts +8 -2
- package/server/store.test.ts +13 -0
- package/server/store.ts +2 -2
- package/shared/activity.test.ts +22 -12
- package/shared/activity.ts +8 -13
- package/shared/agent-page-size.test.ts +11 -0
- package/shared/agent-title-search.test.ts +28 -0
- package/shared/agent-title-search.ts +12 -0
- package/shared/explorer-agent-display.ts +30 -0
- package/shared/format.test.ts +22 -1
- package/shared/format.ts +24 -0
- package/shared/insights.test.ts +38 -18
- package/shared/insights.ts +38 -19
- package/shared/list-agent-pages.test.ts +51 -0
- package/shared/list-agent-pages.ts +31 -0
- package/shared/usage.test.ts +248 -0
- package/shared/usage.ts +327 -11
package/shared/usage.ts
CHANGED
|
@@ -24,6 +24,8 @@ export const usageSummaryRpc = defineRpc({
|
|
|
24
24
|
mcpCalls: z.number().int().nonnegative(),
|
|
25
25
|
mcpFailures: z.number().int().nonnegative(),
|
|
26
26
|
toolCallsByKind: z.record(z.string(), z.number().int().nonnegative()),
|
|
27
|
+
/** User sends in the same filter window (006 / 031). */
|
|
28
|
+
messageCount: z.number().int().nonnegative(),
|
|
27
29
|
}),
|
|
28
30
|
});
|
|
29
31
|
|
|
@@ -168,6 +170,13 @@ export const ProviderUsageItemSchema = z.object({
|
|
|
168
170
|
/** Messages-weighted model ranks (015); empty when no stamped models. */
|
|
169
171
|
models: z.array(ModelByNameItemSchema),
|
|
170
172
|
agentCount: z.number().int().nonnegative(),
|
|
173
|
+
/**
|
|
174
|
+
* Agents with ≥1 coding op in-window (019: file write/edit/delete or mutating shell).
|
|
175
|
+
* Empty (created-only) agents are excluded from coding and chat. See 018/019.
|
|
176
|
+
*/
|
|
177
|
+
codingAgentCount: z.number().int().nonnegative(),
|
|
178
|
+
/** Active non-coding agents: has message or tool_call, but no coding op. */
|
|
179
|
+
chatAgentCount: z.number().int().nonnegative(),
|
|
171
180
|
/** Distinct non-null workspace_id among agents for this provider (same window). */
|
|
172
181
|
workspaceCount: z.number().int().nonnegative(),
|
|
173
182
|
messageCount: z.number().int().nonnegative(),
|
|
@@ -196,6 +205,57 @@ export const usageByProviderRpc = defineRpc({
|
|
|
196
205
|
}),
|
|
197
206
|
});
|
|
198
207
|
|
|
208
|
+
export const AgentUsageItemSchema = z.object({
|
|
209
|
+
agentId: z.string(),
|
|
210
|
+
provider: z.string(),
|
|
211
|
+
/** Registry title; null when unknown. */
|
|
212
|
+
title: z.string().nullable(),
|
|
213
|
+
/** All tool calls (any category). */
|
|
214
|
+
callCount: z.number().int().nonnegative(),
|
|
215
|
+
/** exact + inferred; low excluded (same as UI totals). */
|
|
216
|
+
skillCalls: z.number().int().nonnegative(),
|
|
217
|
+
mcpCalls: z.number().int().nonnegative(),
|
|
218
|
+
shellCalls: z.number().int().nonnegative(),
|
|
219
|
+
fileReads: z.number().int().nonnegative(),
|
|
220
|
+
fileWrites: z.number().int().nonnegative(),
|
|
221
|
+
messageCount: z.number().int().nonnegative(),
|
|
222
|
+
/** 019: at least one coding op in the window. */
|
|
223
|
+
coding: z.boolean(),
|
|
224
|
+
/** Registry creation time; null when the agent is not in the registry. */
|
|
225
|
+
createdAt: z.string().nullable(),
|
|
226
|
+
/** Registry last update time (hook time); null when not in the registry. */
|
|
227
|
+
updatedAt: z.string().nullable(),
|
|
228
|
+
/** Registry archive time; null for active agents (025). */
|
|
229
|
+
archivedAt: z.string().nullable(),
|
|
230
|
+
/** Latest tool call / message time in the window. */
|
|
231
|
+
lastActivityAt: z.string().nullable(),
|
|
232
|
+
});
|
|
233
|
+
export type AgentUsageItem = z.infer<typeof AgentUsageItemSchema>;
|
|
234
|
+
|
|
235
|
+
export const usageAgentsRpc = defineRpc({
|
|
236
|
+
name: "usage.agents",
|
|
237
|
+
input: z.object({
|
|
238
|
+
from: z.string().optional(),
|
|
239
|
+
to: z.string().optional(),
|
|
240
|
+
workspaceId: z.string().optional(),
|
|
241
|
+
}),
|
|
242
|
+
output: z.object({
|
|
243
|
+
items: z.array(AgentUsageItemSchema),
|
|
244
|
+
}),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/** Unarchive via host `refreshAgent` (CLI: `paseo agent reload`). */
|
|
248
|
+
export const usageAgentUnarchiveRpc = defineRpc({
|
|
249
|
+
name: "usage.agent.unarchive",
|
|
250
|
+
input: z.object({
|
|
251
|
+
agentId: z.string().min(1),
|
|
252
|
+
}),
|
|
253
|
+
output: z.object({
|
|
254
|
+
agentId: z.string(),
|
|
255
|
+
ok: z.literal(true),
|
|
256
|
+
}),
|
|
257
|
+
});
|
|
258
|
+
|
|
199
259
|
const PROVIDER_LABELS: Record<string, string> = {
|
|
200
260
|
claude: "Claude",
|
|
201
261
|
opencode: "OpenCode",
|
|
@@ -233,6 +293,137 @@ export function isFileWrite(row: { category: string; detailType: string | null }
|
|
|
233
293
|
);
|
|
234
294
|
}
|
|
235
295
|
|
|
296
|
+
/** Common development commands that usually mutate the filesystem (019). */
|
|
297
|
+
const MUTATING_SHELL_HEADS = new Set([
|
|
298
|
+
"rm",
|
|
299
|
+
"rmdir",
|
|
300
|
+
"mv",
|
|
301
|
+
"cp",
|
|
302
|
+
"mkdir",
|
|
303
|
+
"touch",
|
|
304
|
+
"chmod",
|
|
305
|
+
"chown",
|
|
306
|
+
"ln",
|
|
307
|
+
"unlink",
|
|
308
|
+
"install",
|
|
309
|
+
"tee",
|
|
310
|
+
"truncate",
|
|
311
|
+
"dd",
|
|
312
|
+
"sed",
|
|
313
|
+
"perl",
|
|
314
|
+
"npm",
|
|
315
|
+
"npx",
|
|
316
|
+
"pnpm",
|
|
317
|
+
"yarn",
|
|
318
|
+
"bun",
|
|
319
|
+
"pip",
|
|
320
|
+
"pip3",
|
|
321
|
+
"poetry",
|
|
322
|
+
"uv",
|
|
323
|
+
"cargo",
|
|
324
|
+
"composer",
|
|
325
|
+
"bundle",
|
|
326
|
+
"make",
|
|
327
|
+
"cmake",
|
|
328
|
+
"ninja",
|
|
329
|
+
"tsc",
|
|
330
|
+
"webpack",
|
|
331
|
+
"vite",
|
|
332
|
+
"esbuild",
|
|
333
|
+
"rollup",
|
|
334
|
+
]);
|
|
335
|
+
|
|
336
|
+
/** git subcommands that typically write objects / worktree / index. */
|
|
337
|
+
const GIT_MUTATING_SUBCOMMANDS = new Set([
|
|
338
|
+
"add",
|
|
339
|
+
"commit",
|
|
340
|
+
"checkout",
|
|
341
|
+
"switch",
|
|
342
|
+
"merge",
|
|
343
|
+
"rebase",
|
|
344
|
+
"cherry-pick",
|
|
345
|
+
"stash",
|
|
346
|
+
"clean",
|
|
347
|
+
"reset",
|
|
348
|
+
"restore",
|
|
349
|
+
"mv",
|
|
350
|
+
"rm",
|
|
351
|
+
"pull",
|
|
352
|
+
"push",
|
|
353
|
+
"clone",
|
|
354
|
+
"init",
|
|
355
|
+
"fetch",
|
|
356
|
+
"am",
|
|
357
|
+
"apply",
|
|
358
|
+
"revert",
|
|
359
|
+
"submodule",
|
|
360
|
+
"worktree",
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
const SHELL_REDIRECT_RE = />|>>|\|\s*tee\b/i;
|
|
364
|
+
|
|
365
|
+
/** git flags that take a following argument before the subcommand. */
|
|
366
|
+
const GIT_VALUE_FLAGS = new Set(["-C", "-c", "--git-dir", "--work-tree"]);
|
|
367
|
+
|
|
368
|
+
function shellHeadAndRest(command: string): { head: string; tokens: string[] } {
|
|
369
|
+
const tokens = command.trim().split(/\s+/).filter(Boolean);
|
|
370
|
+
const raw = tokens[0] ?? "";
|
|
371
|
+
const head = raw.replace(/^.*\//, "") || raw;
|
|
372
|
+
return { head, tokens };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function firstGitSubcommand(tokens: readonly string[]): string | undefined {
|
|
376
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
377
|
+
const token = tokens[i]!;
|
|
378
|
+
if (token === "--") {
|
|
379
|
+
return tokens[i + 1];
|
|
380
|
+
}
|
|
381
|
+
if (GIT_VALUE_FLAGS.has(token)) {
|
|
382
|
+
i += 1; // skip flag value
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (token.startsWith("-")) continue;
|
|
386
|
+
return token;
|
|
387
|
+
}
|
|
388
|
+
return undefined;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Heuristic: shell command likely mutates the filesystem (019).
|
|
393
|
+
* Prefers covering common dev write paths; unknown scripts may under-count.
|
|
394
|
+
*/
|
|
395
|
+
export function shellLooksMutating(command: string | null | undefined): boolean {
|
|
396
|
+
if (!command?.trim()) return false;
|
|
397
|
+
if (SHELL_REDIRECT_RE.test(command)) return true;
|
|
398
|
+
|
|
399
|
+
const { head, tokens } = shellHeadAndRest(command);
|
|
400
|
+
if (!head) return false;
|
|
401
|
+
|
|
402
|
+
if (head === "sudo" || head === "doas") {
|
|
403
|
+
const rest = tokens.slice(1).join(" ");
|
|
404
|
+
return rest.length > 0 && shellLooksMutating(rest);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (MUTATING_SHELL_HEADS.has(head)) return true;
|
|
408
|
+
|
|
409
|
+
if (head === "git") {
|
|
410
|
+
const sub = firstGitSubcommand(tokens);
|
|
411
|
+
return sub != null && GIT_MUTATING_SUBCOMMANDS.has(sub);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Session coding op (019): native file write/edit/delete, or mutating shell. */
|
|
418
|
+
export function isCodingOp(row: {
|
|
419
|
+
category: string;
|
|
420
|
+
detailType: string | null;
|
|
421
|
+
command?: string | null;
|
|
422
|
+
}): boolean {
|
|
423
|
+
if (isFileWrite(row)) return true;
|
|
424
|
+
return isShellCall(row) && shellLooksMutating(row.command);
|
|
425
|
+
}
|
|
426
|
+
|
|
236
427
|
/** Aggregate tool_calls by normalizeProvider(provider).
|
|
237
428
|
* `agentCount` / `workspaceCount` come from `agents` (created registry), not tool_call distinct ids.
|
|
238
429
|
*/
|
|
@@ -257,7 +448,7 @@ export function aggregateByProvider(
|
|
|
257
448
|
provider: string;
|
|
258
449
|
workspaceId?: string | null;
|
|
259
450
|
}> = [],
|
|
260
|
-
messages: ReadonlyArray<{ provider: string; model?: string | null }> = [],
|
|
451
|
+
messages: ReadonlyArray<{ agentId?: string; provider: string; model?: string | null }> = [],
|
|
261
452
|
): {
|
|
262
453
|
totals: {
|
|
263
454
|
shellCalls: number;
|
|
@@ -271,7 +462,14 @@ export function aggregateByProvider(
|
|
|
271
462
|
} {
|
|
272
463
|
type Acc = Omit<
|
|
273
464
|
ProviderUsageItem,
|
|
274
|
-
|
|
465
|
+
| "skills"
|
|
466
|
+
| "mcpTools"
|
|
467
|
+
| "shellTop"
|
|
468
|
+
| "models"
|
|
469
|
+
| "agentCount"
|
|
470
|
+
| "codingAgentCount"
|
|
471
|
+
| "chatAgentCount"
|
|
472
|
+
| "workspaceCount"
|
|
275
473
|
> & {
|
|
276
474
|
agents: Set<string>;
|
|
277
475
|
workspaces: Set<string>;
|
|
@@ -299,6 +497,8 @@ export function aggregateByProvider(
|
|
|
299
497
|
};
|
|
300
498
|
const map = new Map<string, Acc>();
|
|
301
499
|
const allWorkspaces = new Set<string>();
|
|
500
|
+
const codingAgentIds = new Set<string>();
|
|
501
|
+
const activeAgentIds = new Set<string>();
|
|
302
502
|
const totals = {
|
|
303
503
|
shellCalls: 0,
|
|
304
504
|
fileReads: 0,
|
|
@@ -339,6 +539,7 @@ export function aggregateByProvider(
|
|
|
339
539
|
const provider = normalizeProvider(row.provider);
|
|
340
540
|
const acc = ensure(provider);
|
|
341
541
|
acc.callCount += 1;
|
|
542
|
+
activeAgentIds.add(row.agentId);
|
|
342
543
|
|
|
343
544
|
if (row.category === "skill") {
|
|
344
545
|
acc.skillRows.push(row);
|
|
@@ -378,6 +579,9 @@ export function aggregateByProvider(
|
|
|
378
579
|
acc.fileWrites += 1;
|
|
379
580
|
totals.fileWrites += 1;
|
|
380
581
|
}
|
|
582
|
+
if (isCodingOp(row)) {
|
|
583
|
+
codingAgentIds.add(row.agentId);
|
|
584
|
+
}
|
|
381
585
|
}
|
|
382
586
|
|
|
383
587
|
for (const agent of agents) {
|
|
@@ -395,20 +599,35 @@ export function aggregateByProvider(
|
|
|
395
599
|
const acc = ensure(normalizeProvider(message.provider));
|
|
396
600
|
acc.messageCount += 1;
|
|
397
601
|
acc.messageRows.push({ model: message.model });
|
|
602
|
+
const agentId = message.agentId?.trim();
|
|
603
|
+
if (agentId) activeAgentIds.add(agentId);
|
|
398
604
|
}
|
|
399
605
|
|
|
400
606
|
totals.workspaceCount = allWorkspaces.size;
|
|
401
607
|
|
|
402
608
|
const providers = [...map.values()]
|
|
403
|
-
.map(({ agents: agentSet, workspaces, skillRows, mcpRows, shellRows, messageRows, ...rest }) =>
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
609
|
+
.map(({ agents: agentSet, workspaces, skillRows, mcpRows, shellRows, messageRows, ...rest }) => {
|
|
610
|
+
let codingAgentCount = 0;
|
|
611
|
+
let chatAgentCount = 0;
|
|
612
|
+
for (const id of agentSet) {
|
|
613
|
+
if (codingAgentIds.has(id)) {
|
|
614
|
+
codingAgentCount += 1;
|
|
615
|
+
} else if (activeAgentIds.has(id)) {
|
|
616
|
+
chatAgentCount += 1;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
...rest,
|
|
621
|
+
agentCount: agentSet.size,
|
|
622
|
+
codingAgentCount,
|
|
623
|
+
chatAgentCount,
|
|
624
|
+
workspaceCount: workspaces.size,
|
|
625
|
+
skills: aggregateSkillsByName(skillRows),
|
|
626
|
+
mcpTools: aggregateMcpByTool(mcpRows),
|
|
627
|
+
shellTop: aggregateShellTop(shellRows),
|
|
628
|
+
models: aggregateModelsByName(messageRows),
|
|
629
|
+
};
|
|
630
|
+
})
|
|
412
631
|
.sort(
|
|
413
632
|
(a, b) =>
|
|
414
633
|
b.callCount - a.callCount ||
|
|
@@ -419,6 +638,103 @@ export function aggregateByProvider(
|
|
|
419
638
|
return { totals, providers };
|
|
420
639
|
}
|
|
421
640
|
|
|
641
|
+
/** Aggregate tool_calls + user_messages per agent, enriched with the agents registry (024). */
|
|
642
|
+
export function aggregateAgents(
|
|
643
|
+
rows: ReadonlyArray<{
|
|
644
|
+
agentId: string;
|
|
645
|
+
provider: string;
|
|
646
|
+
category: string;
|
|
647
|
+
confidence: string | null;
|
|
648
|
+
detailType: string | null;
|
|
649
|
+
command?: string | null;
|
|
650
|
+
ts: string | null;
|
|
651
|
+
ingestedAt: string;
|
|
652
|
+
}>,
|
|
653
|
+
agents: ReadonlyArray<{
|
|
654
|
+
agentId: string;
|
|
655
|
+
provider: string;
|
|
656
|
+
title?: string | null;
|
|
657
|
+
createdAt?: string | null;
|
|
658
|
+
updatedAt?: string | null;
|
|
659
|
+
archivedAt?: string | null;
|
|
660
|
+
}> = [],
|
|
661
|
+
messages: ReadonlyArray<{
|
|
662
|
+
agentId?: string;
|
|
663
|
+
provider: string;
|
|
664
|
+
ts?: string | null;
|
|
665
|
+
ingestedAt?: string;
|
|
666
|
+
}> = [],
|
|
667
|
+
): AgentUsageItem[] {
|
|
668
|
+
const map = new Map<string, AgentUsageItem>();
|
|
669
|
+
|
|
670
|
+
function ensure(agentId: string, provider: string): AgentUsageItem {
|
|
671
|
+
let acc = map.get(agentId);
|
|
672
|
+
if (!acc) {
|
|
673
|
+
acc = {
|
|
674
|
+
agentId,
|
|
675
|
+
provider: normalizeProvider(provider),
|
|
676
|
+
title: null,
|
|
677
|
+
callCount: 0,
|
|
678
|
+
skillCalls: 0,
|
|
679
|
+
mcpCalls: 0,
|
|
680
|
+
shellCalls: 0,
|
|
681
|
+
fileReads: 0,
|
|
682
|
+
fileWrites: 0,
|
|
683
|
+
messageCount: 0,
|
|
684
|
+
coding: false,
|
|
685
|
+
createdAt: null,
|
|
686
|
+
updatedAt: null,
|
|
687
|
+
archivedAt: null,
|
|
688
|
+
lastActivityAt: null,
|
|
689
|
+
};
|
|
690
|
+
map.set(agentId, acc);
|
|
691
|
+
}
|
|
692
|
+
return acc;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function touch(acc: AgentUsageItem, at: string | null | undefined): void {
|
|
696
|
+
if (at && (!acc.lastActivityAt || at > acc.lastActivityAt)) acc.lastActivityAt = at;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
for (const row of rows) {
|
|
700
|
+
const acc = ensure(row.agentId, row.provider);
|
|
701
|
+
acc.callCount += 1;
|
|
702
|
+
if (row.category === "skill") {
|
|
703
|
+
if (row.confidence !== "low") acc.skillCalls += 1;
|
|
704
|
+
} else if (row.category === "mcp") {
|
|
705
|
+
acc.mcpCalls += 1;
|
|
706
|
+
}
|
|
707
|
+
if (isShellCall(row)) acc.shellCalls += 1;
|
|
708
|
+
if (isFileRead(row)) acc.fileReads += 1;
|
|
709
|
+
if (isFileWrite(row)) acc.fileWrites += 1;
|
|
710
|
+
if (isCodingOp(row)) acc.coding = true;
|
|
711
|
+
touch(acc, row.ts ?? row.ingestedAt);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
for (const agent of agents) {
|
|
715
|
+
const acc = ensure(agent.agentId, agent.provider);
|
|
716
|
+
acc.title = agent.title?.trim() || acc.title;
|
|
717
|
+
acc.createdAt = agent.createdAt ?? acc.createdAt;
|
|
718
|
+
acc.updatedAt = agent.updatedAt ?? acc.updatedAt;
|
|
719
|
+
acc.archivedAt = agent.archivedAt ?? acc.archivedAt;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
for (const message of messages) {
|
|
723
|
+
const agentId = message.agentId?.trim();
|
|
724
|
+
if (!agentId) continue;
|
|
725
|
+
const acc = ensure(agentId, message.provider);
|
|
726
|
+
acc.messageCount += 1;
|
|
727
|
+
touch(acc, message.ts ?? message.ingestedAt);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return [...map.values()].sort(
|
|
731
|
+
(a, b) =>
|
|
732
|
+
b.callCount + b.messageCount - (a.callCount + a.messageCount) ||
|
|
733
|
+
(b.lastActivityAt ?? "").localeCompare(a.lastActivityAt ?? "") ||
|
|
734
|
+
(a.title ?? a.agentId).localeCompare(b.title ?? b.agentId),
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
|
|
422
738
|
/** Aggregate user messages by model id (015). Null/blank models are skipped. */
|
|
423
739
|
export function aggregateModelsByName(
|
|
424
740
|
messages: ReadonlyArray<{ model?: string | null }>,
|