@koinzhang/paseo-plugin-activity 0.6.0 → 0.8.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/README.md +18 -11
  3. package/client/activity-heatmap.tsx +115 -74
  4. package/client/agent-creations.tsx +100 -90
  5. package/client/attention-pill.tsx +17 -6
  6. package/client/attention-popover.tsx +19 -23
  7. package/client/design-tokens.test.ts +39 -0
  8. package/client/design-tokens.ts +180 -0
  9. package/client/formatted-time.tsx +4 -4
  10. package/client/global-surface.tsx +243 -268
  11. package/client/header-button.ts +136 -0
  12. package/client/hourly-activity-timeline.tsx +153 -103
  13. package/client/panel-visibility.test.ts +25 -0
  14. package/client/panel-visibility.ts +45 -0
  15. package/client/panel.tsx +94 -111
  16. package/client/pill.tsx +1 -1
  17. package/client/provider-dropdown.tsx +134 -0
  18. package/client/provider-filter.test.ts +17 -13
  19. package/client/provider-filter.ts +5 -7
  20. package/client/rank-color.ts +3 -3
  21. package/client/ranking-bars.tsx +294 -0
  22. package/client/sidebar-item.tsx +15 -0
  23. package/client/ui.tsx +351 -0
  24. package/client/usage-popover.tsx +72 -137
  25. package/client/usage-stats.tsx +29 -11
  26. package/client/use-agent-turn-end.ts +2 -1
  27. package/client/use-app-language.ts +17 -0
  28. package/client/web.ts +73 -18
  29. package/client/workspace/agent-row.tsx +28 -28
  30. package/client/workspace/agents-section.tsx +42 -57
  31. package/client/workspace/constants.ts +8 -6
  32. package/client/workspace/display-menu.tsx +6 -5
  33. package/client/workspace/filters.test.ts +1 -1
  34. package/client/workspace/filters.ts +4 -2
  35. package/client/workspace/panel.tsx +96 -104
  36. package/client/workspace/rank-section.tsx +40 -65
  37. package/client/workspace/running-indicator.tsx +1 -1
  38. package/client/workspace/terminals-section.tsx +24 -12
  39. package/index.client.tsx +53 -31
  40. package/index.server.ts +55 -73
  41. package/package.json +3 -3
  42. package/paseo-plugin.json +2 -1
  43. package/server/agents.ts +20 -2
  44. package/server/background-sync.ts +34 -4
  45. package/server/handlers-query.test.ts +27 -1
  46. package/server/handlers.ts +75 -31
  47. package/server/host-types.ts +6 -6
  48. package/server/ingest.test.ts +8 -0
  49. package/server/messages.test.ts +96 -1
  50. package/server/prompt-dedupe.ts +52 -0
  51. package/server/rpc-cache.test.ts +74 -0
  52. package/server/rpc-cache.ts +48 -0
  53. package/server/store.test.ts +122 -0
  54. package/server/store.ts +313 -19
  55. package/server/ttl-cache.ts +3 -0
  56. package/server/turn-ingest.test.ts +180 -0
  57. package/server/turn-ingest.ts +71 -0
  58. package/shared/activity.test.ts +36 -0
  59. package/shared/activity.ts +37 -0
  60. package/shared/classify.test.ts +1 -10
  61. package/shared/classify.ts +3 -10
  62. package/shared/format.ts +10 -7
  63. package/shared/i18n.test.ts +34 -0
  64. package/shared/i18n.ts +363 -0
  65. package/shared/insights.test.ts +120 -81
  66. package/shared/insights.ts +125 -64
  67. package/shared/usage.test.ts +121 -0
  68. package/shared/usage.ts +191 -2
@@ -0,0 +1,74 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { createRpcCache } from "./rpc-cache.ts";
4
+
5
+ function fixture(options: { ttlMs?: number; maxEntries?: number } = {}) {
6
+ let generation = 0;
7
+ let clock = 0;
8
+ let calls = 0;
9
+ const cache = createRpcCache({
10
+ generation: () => generation,
11
+ now: () => clock,
12
+ ...options,
13
+ });
14
+ const handler = cache.wrap("usage.test", async (input: { n: number }) => {
15
+ calls += 1;
16
+ return input.n * 2;
17
+ });
18
+ return {
19
+ handler,
20
+ cache,
21
+ calls: () => calls,
22
+ bump: () => { generation += 1; },
23
+ advance: (ms: number) => { clock += ms; },
24
+ };
25
+ }
26
+
27
+ test("identical input hits the cache; different input does not", async () => {
28
+ const f = fixture();
29
+ assert.equal(await f.handler({ n: 1 }, undefined), 2);
30
+ assert.equal(await f.handler({ n: 1 }, undefined), 2);
31
+ assert.equal(f.calls(), 1);
32
+ await f.handler({ n: 2 }, undefined);
33
+ assert.equal(f.calls(), 2);
34
+ });
35
+
36
+ test("store writes and TTL expiry invalidate", async () => {
37
+ const f = fixture({ ttlMs: 1_000 });
38
+ await f.handler({ n: 1 }, undefined);
39
+ f.bump();
40
+ await f.handler({ n: 1 }, undefined);
41
+ assert.equal(f.calls(), 2);
42
+ f.advance(999);
43
+ await f.handler({ n: 1 }, undefined);
44
+ assert.equal(f.calls(), 2);
45
+ f.advance(1);
46
+ await f.handler({ n: 1 }, undefined);
47
+ assert.equal(f.calls(), 3);
48
+ });
49
+
50
+ test("evicts least recently used entries beyond the cap", async () => {
51
+ const f = fixture({ maxEntries: 2 });
52
+ await f.handler({ n: 1 }, undefined);
53
+ await f.handler({ n: 2 }, undefined);
54
+ await f.handler({ n: 1 }, undefined);
55
+ await f.handler({ n: 3 }, undefined);
56
+ assert.equal(f.calls(), 3);
57
+ await f.handler({ n: 1 }, undefined);
58
+ assert.equal(f.calls(), 3, "recently used entry survives");
59
+ await f.handler({ n: 2 }, undefined);
60
+ assert.equal(f.calls(), 4, "least recently used entry was evicted");
61
+ });
62
+
63
+ test("rejected results are not cached", async () => {
64
+ let calls = 0;
65
+ const cache = createRpcCache({ generation: () => 0 });
66
+ const handler = cache.wrap("usage.fail", async () => {
67
+ calls += 1;
68
+ if (calls === 1) throw new Error("boom");
69
+ return "ok";
70
+ });
71
+ await assert.rejects(handler({}, undefined), /boom/);
72
+ assert.equal(await handler({}, undefined), "ok");
73
+ assert.equal(calls, 2);
74
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Memoize read RPC results until the store is written or the TTL passes.
3
+ *
4
+ * Panels poll every 15s with identical inputs; without this each poll re-reads
5
+ * and re-aggregates whole tables synchronously on the plugin process.
6
+ */
7
+ export function createRpcCache(options: {
8
+ generation: () => number;
9
+ ttlMs?: number;
10
+ maxEntries?: number;
11
+ now?: () => number;
12
+ }) {
13
+ const ttlMs = options.ttlMs ?? 30_000;
14
+ const maxEntries = options.maxEntries ?? 64;
15
+ const now = options.now ?? Date.now;
16
+ const entries = new Map<string, { generation: number; at: number; value: Promise<unknown> }>();
17
+
18
+ function wrap<I, C, O>(
19
+ name: string,
20
+ handler: (input: I, context: C) => Promise<O>,
21
+ ): (input: I, context: C) => Promise<O> {
22
+ return (input, context) => {
23
+ const key = `${name}\0${JSON.stringify(input ?? null)}`;
24
+ const generation = options.generation();
25
+ const at = now();
26
+ const hit = entries.get(key);
27
+ if (hit && hit.generation === generation && at - hit.at < ttlMs) {
28
+ entries.delete(key);
29
+ entries.set(key, hit);
30
+ return hit.value as Promise<O>;
31
+ }
32
+ const value = handler(input, context);
33
+ entries.delete(key);
34
+ entries.set(key, { generation, at, value });
35
+ value.catch(() => {
36
+ if (entries.get(key)?.value === value) entries.delete(key);
37
+ });
38
+ while (entries.size > maxEntries) {
39
+ const oldest = entries.keys().next().value;
40
+ if (oldest === undefined) break;
41
+ entries.delete(oldest);
42
+ }
43
+ return value;
44
+ };
45
+ }
46
+
47
+ return { wrap, clear: () => entries.clear() };
48
+ }
@@ -232,3 +232,125 @@ test("sqlite: epoch replace deletes canonical user messages", () => {
232
232
  assert.equal(store.selectUserMessages({ agentId: "agent-1" })[0]?.messageId, "real-id");
233
233
  store.close();
234
234
  });
235
+
236
+ for (const driver of ["sqlite", "jsonl"] as const) {
237
+ test(`${driver}: selectRecent / countRows page newest-first with scopes (064)`, () => {
238
+ const store = createUsageStore({ dir: tempDir(), driver });
239
+ store.upsertMany([
240
+ row({ callId: "a", ts: "2026-09-18T01:00:00.000Z", category: "skill", skillName: "alpha", confidence: "exact" }),
241
+ row({ callId: "b", ts: "2026-09-18T03:00:00.000Z", category: "skill", skillName: "low", confidence: "low" }),
242
+ row({ callId: "c", ts: "2026-09-18T02:00:00.000Z", category: "skill", skillName: " ", confidence: "exact" }),
243
+ row({ callId: "d", ts: null, ingestedAt: "2026-09-18T04:00:00.000Z", category: "skill", skillName: "beta", confidence: "inferred" }),
244
+ row({ callId: "e", ts: "2026-09-18T05:00:00.000Z", workspaceId: "ws-2", category: "skill", skillName: "other", confidence: "exact" }),
245
+ row({ callId: "f", ts: "2026-09-18T02:00:00.000Z", category: "mcp", mcpServer: "paseo", mcpTool: "list" }),
246
+ row({ callId: "g", ts: "2026-09-18T06:00:00.000Z", category: "mcp", mcpServer: "paseo", mcpTool: null }),
247
+ ]);
248
+ const skill = { workspaceId: "ws-1", category: "skill" as const };
249
+ assert.deepEqual(
250
+ store.selectRecent(skill, { limit: 10, scope: "skill-named" }).map((r) => r.callId),
251
+ ["d", "a"],
252
+ );
253
+ assert.deepEqual(
254
+ store.selectRecent({ workspaceId: "ws-1", category: "mcp" }, { limit: 10, scope: "mcp-named" })
255
+ .map((r) => r.callId),
256
+ ["f"],
257
+ );
258
+ assert.deepEqual(
259
+ store.selectRecent({ workspaceId: "ws-1" }, { limit: 2, offset: 1 }).map((r) => r.callId),
260
+ ["d", "b"],
261
+ );
262
+ assert.equal(store.countRows({ workspaceId: "ws-1" }), 6);
263
+ assert.equal(store.countRows(skill), 4);
264
+ store.close();
265
+ });
266
+
267
+ test(`${driver}: generation, activity spans and terminal call ids (064)`, () => {
268
+ const store = createUsageStore({ dir: tempDir(), driver });
269
+ const g0 = store.generation();
270
+ store.upsertMany([
271
+ row({ callId: "x", ts: "2026-09-18T05:00:00.000Z", status: "completed", provider: "codex", workspaceId: "late" }),
272
+ row({ callId: "y", ts: "2026-09-18T01:00:00.000Z", status: "running", provider: "claude", workspaceId: "early" }),
273
+ row({ agentId: "agent-2", callId: "z", ts: "2026-09-18T02:00:00.000Z", status: "failed" }),
274
+ ]);
275
+ assert.ok(store.generation() > g0);
276
+ const g1 = store.generation();
277
+ store.select();
278
+ assert.equal(store.generation(), g1, "reads do not bump generation");
279
+ const spans = store.agentActivitySpans().sort((a, b) => a.agentId.localeCompare(b.agentId));
280
+ assert.deepEqual(spans[0], {
281
+ agentId: "agent-1",
282
+ provider: "claude",
283
+ workspaceId: "early",
284
+ firstAt: "2026-09-18T01:00:00.000Z",
285
+ lastAt: "2026-09-18T05:00:00.000Z",
286
+ });
287
+ assert.equal(spans.length, 2);
288
+ assert.deepEqual([...store.terminalCallIds("agent-1")], ["x"]);
289
+ assert.deepEqual([...store.terminalCallIds("agent-2")], ["z"]);
290
+ store.close();
291
+ });
292
+
293
+ test(`${driver}: rescans keep the earliest event time, never after first ingest (074)`, () => {
294
+ const store = createUsageStore({ dir: tempDir(), driver });
295
+ const ts = (callId: string) => store.getRow("agent-1", callId)?.ts ?? null;
296
+ store.upsertMany([
297
+ row({ callId: "known", ts: "2026-09-18T10:00:00.000Z" }),
298
+ row({ callId: "live", ts: null }),
299
+ row({ callId: "live-real", ts: null }),
300
+ ]);
301
+ store.upsertMany([
302
+ row({ callId: "known", ts: "2026-09-20T08:00:00.000Z", ingestedAt: "2026-09-20T08:00:01.000Z" }),
303
+ row({ callId: "live", ts: "2026-09-20T08:00:00.000Z", ingestedAt: "2026-09-20T08:00:01.000Z" }),
304
+ row({ callId: "live-real", ts: "2026-09-18T11:30:00.000Z" }),
305
+ ]);
306
+ assert.equal(ts("known"), "2026-09-18T10:00:00.000Z");
307
+ assert.equal(ts("live"), null);
308
+ assert.equal(ts("live-real"), "2026-09-18T11:30:00.000Z");
309
+ store.upsertMany([row({ callId: "known", ts: "2026-09-18T09:00:00.000Z" }), row({ callId: "known", ts: null })]);
310
+ assert.equal(ts("known"), "2026-09-18T09:00:00.000Z");
311
+
312
+ const message = {
313
+ agentId: "agent-1",
314
+ messageId: "m1",
315
+ workspaceId: "ws",
316
+ provider: "cursor",
317
+ model: null,
318
+ turnId: null,
319
+ seq: 1,
320
+ ts: null,
321
+ ingestedAt: "2026-09-18T12:00:00.000Z",
322
+ };
323
+ store.upsertUserMessages([message]);
324
+ store.upsertUserMessages([{ ...message, ts: "2026-09-20T08:00:00.000Z", ingestedAt: "2026-09-20T08:00:01.000Z" }]);
325
+ assert.equal(store.selectUserMessages({ agentId: "agent-1" })[0]?.ts, null);
326
+ store.upsertUserMessages([{ ...message, ts: "2026-09-18T11:00:00.000Z" }]);
327
+ assert.equal(store.selectUserMessages({ agentId: "agent-1" })[0]?.ts, "2026-09-18T11:00:00.000Z");
328
+ store.close();
329
+ });
330
+
331
+ test(`${driver}: reopening clears event times later than first ingest (074)`, () => {
332
+ const dir = tempDir();
333
+ const store = createUsageStore({ dir, driver });
334
+ store.upsertMany([
335
+ row({ callId: "stamped", ts: "2026-09-20T08:00:00.000Z" }),
336
+ row({ callId: "fine", ts: "2026-09-18T11:00:00.000Z" }),
337
+ ]);
338
+ store.upsertUserMessages([{
339
+ agentId: "agent-1",
340
+ messageId: "m1",
341
+ workspaceId: "ws",
342
+ provider: "cursor",
343
+ model: null,
344
+ turnId: null,
345
+ seq: 1,
346
+ ts: "2026-09-20T08:00:00.000Z",
347
+ ingestedAt: "2026-09-18T12:00:00.000Z",
348
+ }]);
349
+ store.close();
350
+ const reopened = createUsageStore({ dir, driver });
351
+ assert.equal(reopened.getRow("agent-1", "stamped")?.ts, null);
352
+ assert.equal(reopened.getRow("agent-1", "fine")?.ts, "2026-09-18T11:00:00.000Z");
353
+ assert.equal(reopened.selectUserMessages({ agentId: "agent-1" })[0]?.ts, null);
354
+ reopened.close();
355
+ });
356
+ }