@koinzhang/paseo-plugin-activity 0.4.0 → 0.6.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 (52) hide show
  1. package/CHANGELOG.md +61 -2
  2. package/README.md +3 -3
  3. package/client/activity-heatmap.tsx +17 -25
  4. package/client/agent-creations.tsx +207 -0
  5. package/client/agent-directory.test.ts +191 -0
  6. package/client/agent-directory.ts +150 -0
  7. package/client/attention-pill.tsx +17 -105
  8. package/client/color-mix.test.ts +27 -0
  9. package/client/color-mix.ts +38 -0
  10. package/client/fit-text.test.ts +41 -0
  11. package/client/fit-text.ts +33 -0
  12. package/client/global-surface.tsx +104 -31
  13. package/client/hourly-activity-timeline.tsx +392 -0
  14. package/client/measured-width.ts +72 -0
  15. package/client/pill-directory.ts +20 -68
  16. package/client/range.test.ts +44 -0
  17. package/client/range.ts +14 -0
  18. package/client/rank-color.test.ts +108 -14
  19. package/client/rank-color.ts +261 -48
  20. package/client/usage-stats.tsx +116 -5
  21. package/client/use-agent-turn-end.ts +19 -2
  22. package/client/use-workspace-agent-statuses.ts +18 -42
  23. package/client/workspace/constants.ts +2 -0
  24. package/client/workspace/host-archive-sync.test.ts +46 -0
  25. package/client/workspace/host-archive-sync.ts +15 -0
  26. package/client/workspace/list-host-agents.test.ts +11 -63
  27. package/client/workspace/list-host-agents.ts +4 -58
  28. package/client/workspace/panel.tsx +99 -12
  29. package/client/workspace/rank-section.tsx +150 -11
  30. package/index.server.ts +30 -0
  31. package/package.json +3 -3
  32. package/paseo-plugin.json +1 -1
  33. package/server/background-sync.test.ts +43 -0
  34. package/server/background-sync.ts +9 -0
  35. package/server/handlers-query.test.ts +225 -0
  36. package/server/handlers.ts +117 -0
  37. package/shared/activity.test.ts +123 -6
  38. package/shared/activity.ts +103 -5
  39. package/shared/classify.test.ts +10 -0
  40. package/shared/classify.ts +10 -0
  41. package/shared/explorer-agent-display.test.ts +61 -0
  42. package/shared/explorer-agent-display.ts +21 -2
  43. package/shared/format.test.ts +28 -3
  44. package/shared/format.ts +22 -2
  45. package/shared/insights.test.ts +113 -70
  46. package/shared/insights.ts +53 -39
  47. package/shared/usage.test.ts +209 -0
  48. package/shared/usage.ts +283 -1
  49. package/client/pill-directory.test.ts +0 -92
  50. package/client/workspace/agent-live-status-sync.tsx +0 -103
  51. package/client/workspace/status-cache.test.ts +0 -62
  52. package/client/workspace/status-cache.ts +0 -23
@@ -1,103 +0,0 @@
1
- import { useAgent, useWorkspace } from "@getpaseo/plugin/client";
2
- import { useQueryClient } from "@tanstack/react-query";
3
- import { useEffect, type ReactNode } from "react";
4
- import { workspaceAgentStatusQueryKey } from "../use-workspace-agent-statuses.ts";
5
- import type { AgentStatusInfo } from "./constants.ts";
6
- import { updateWorkspaceStatusCache } from "./status-cache.ts";
7
-
8
- type LiveFields = {
9
- status: AgentStatusInfo["status"];
10
- updatedAt: string | null;
11
- requiresAttention: boolean;
12
- attentionReason: AgentStatusInfo["attentionReason"];
13
- parentAgentId: string | null;
14
- };
15
-
16
- function sameLiveFields(current: AgentStatusInfo | undefined, next: LiveFields): boolean {
17
- if (!current) return false;
18
- return (
19
- current.status === next.status &&
20
- current.updatedAt === next.updatedAt &&
21
- current.requiresAttention === next.requiresAttention &&
22
- current.attentionReason === next.attentionReason &&
23
- current.parentAgentId === next.parentAgentId
24
- );
25
- }
26
-
27
- /** Push one host-normalized snapshot into the workspace status query cache (043). */
28
- function AgentLiveStatusSync({
29
- agentId,
30
- workspaceId,
31
- }: {
32
- agentId: string;
33
- workspaceId: string;
34
- }): null {
35
- const queryClient = useQueryClient();
36
- const projectId = useWorkspace(workspaceId, (workspace) => workspace.projectId);
37
- const queryKey = workspaceAgentStatusQueryKey(workspaceId, projectId);
38
- const live = useAgent(agentId, (agent) => ({
39
- status: agent.status,
40
- updatedAt: agent.updatedAt,
41
- requiresAttention: agent.requiresAttention,
42
- attentionReason: agent.attentionReason,
43
- parentAgentId: agent.parentAgentId,
44
- }));
45
-
46
- useEffect(() => {
47
- const previous = queryClient.getQueryData<Record<string, AgentStatusInfo>>(queryKey);
48
- if (!previous) return;
49
-
50
- if (live == null) {
51
- if (!(agentId in previous) || previous[agentId]?.status === "closed") return;
52
- updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, {
53
- kind: "upsert",
54
- agent: { id: agentId, workspaceId, status: "closed" },
55
- });
56
- return;
57
- }
58
-
59
- const next: LiveFields = {
60
- status: live.status,
61
- updatedAt: live.updatedAt,
62
- requiresAttention: live.requiresAttention,
63
- attentionReason: live.attentionReason,
64
- parentAgentId: live.parentAgentId,
65
- };
66
- if (sameLiveFields(previous[agentId], next)) return;
67
-
68
- updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, {
69
- kind: "upsert",
70
- agent: {
71
- id: agentId,
72
- workspaceId,
73
- status: live.status,
74
- updatedAt: live.updatedAt,
75
- requiresAttention: live.requiresAttention,
76
- attentionReason: live.attentionReason,
77
- parentAgentId: live.parentAgentId,
78
- },
79
- });
80
- }, [agentId, live, queryClient, queryKey, workspaceId]);
81
-
82
- return null;
83
- }
84
-
85
- /**
86
- * Official real-time path for lifecycle / attention fields without owning
87
- * `agents.list({ subscribe })`. pendingPermissions still come from list polls.
88
- */
89
- export function WorkspaceAgentLiveStatusSync({
90
- agentIds,
91
- workspaceId,
92
- }: {
93
- agentIds: ReadonlyArray<string>;
94
- workspaceId: string;
95
- }): ReactNode {
96
- return (
97
- <>
98
- {agentIds.map((agentId) => (
99
- <AgentLiveStatusSync key={agentId} agentId={agentId} workspaceId={workspaceId} />
100
- ))}
101
- </>
102
- );
103
- }
@@ -1,62 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { test } from "node:test";
3
- import { QueryClient } from "@tanstack/react-query";
4
- import { updateWorkspaceStatusCache } from "./status-cache.ts";
5
- import { agentStatusInfo, loadWorkspaceAgentStatuses, type HostAgentUpdate } from "./list-host-agents.ts";
6
- import { agentUpdatedAt } from "./constants.ts";
7
- import type { AgentUsageItem } from "../../shared/usage.ts";
8
-
9
- test("late poll cannot erase live permission or closed-on-remove; cancellation preserves earlier pushes", async () => {
10
- const client = new QueryClient();
11
- const key = ["activity", "workspace-agent-status", "w"];
12
- const stale = { a: agentStatusInfo({ id: "a", workspaceId: "w" }), b: agentStatusInfo({ id: "b", workspaceId: "w", status: "idle" }) };
13
- client.setQueryData(key, stale);
14
- let finish!: (value: typeof stale) => void;
15
- const pending = client.fetchQuery({ queryKey: key, queryFn: () => new Promise<typeof stale>(resolve => { finish = resolve; }) });
16
- updateWorkspaceStatusCache(client, key, "w", { kind: "upsert", agent: { id: "a", workspaceId: "w", pendingPermissions: [{}] } });
17
- updateWorkspaceStatusCache(client, key, "w", { kind: "remove", agentId: "b" });
18
- finish(stale);
19
- await pending;
20
- await Promise.resolve();
21
- const current = client.getQueryData<typeof stale>(key)!;
22
- assert.equal(current.a.permissionCount, 1);
23
- assert.equal(current.b?.status, "closed");
24
- assert.equal(client.getQueryState(key)?.status, "success");
25
- assert.equal(client.getQueryState(key)?.fetchStatus, "idle");
26
- client.clear();
27
- });
28
-
29
- test("first paginated load replays upserts and removes and releases its listener", async () => {
30
- let listener!: (update: HostAgentUpdate) => void;
31
- let unsubscribed = false;
32
- let pages = 0;
33
- const map = await loadWorkspaceAgentStatuses({ agents: {
34
- subscribe: (handler) => { listener = handler; return () => { unsubscribed = true; }; },
35
- list: async () => {
36
- pages++;
37
- if (pages === 1) return { entries: [{ agent: { id: "a", workspaceId: "w" } }], pageInfo: { hasMore: true, nextCursor: "next" } };
38
- listener({ kind: "upsert", agent: { id: "a", workspaceId: "w", pendingPermissions: [{}] } });
39
- listener({ kind: "remove", agentId: "b" });
40
- return { entries: [{ agent: { id: "b", workspaceId: "w", status: "idle" } }], pageInfo: { hasMore: false, nextCursor: null } };
41
- },
42
- } }, "w");
43
- assert.equal(map.a?.permissionCount, 1);
44
- assert.equal(map.b?.status, "closed");
45
- assert.equal(unsubscribed, true);
46
- });
47
-
48
- test("failed load releases its listener", async () => {
49
- let unsubscribed = false;
50
- await assert.rejects(loadWorkspaceAgentStatuses({ agents: {
51
- subscribe: () => () => { unsubscribed = true; },
52
- list: async () => { throw new Error("offline"); },
53
- } }, "w"), /offline/);
54
- assert.equal(unsubscribed, true);
55
- });
56
-
57
- test("live updatedAt takes precedence over old database sync timestamps", () => {
58
- const item = { agentId: "a", updatedAt: "2026-09-19T12:00:00Z", lastActivityAt: "2026-01-01T00:00:00Z" } as AgentUsageItem;
59
- const live = { a: agentStatusInfo({ id: "a", updatedAt: "2026-01-02T00:00:00Z" }) };
60
- assert.equal(agentUpdatedAt(item, live), "2026-01-02T00:00:00Z");
61
- assert.equal(agentUpdatedAt(item, undefined), item.updatedAt);
62
- });
@@ -1,23 +0,0 @@
1
- import type { QueryClient, QueryKey } from "@tanstack/react-query";
2
- import type { AgentStatusInfo } from "./constants.ts";
3
- import { applyAgentStatusUpdate, type HostAgentUpdate } from "./list-host-agents.ts";
4
-
5
- /** Cancel stale reads before publishing live state; the loader buffers first-load events. */
6
- export function updateWorkspaceStatusCache(
7
- queryClient: QueryClient, queryKey: QueryKey, workspaceId: string, update: HostAgentUpdate,
8
- ): void {
9
- const previous = queryClient.getQueryData<Record<string, AgentStatusInfo>>(queryKey);
10
- if (!previous) return;
11
- const id = update.kind === "remove" ? update.agentId : update.agent.id;
12
- if (!(id in previous)) {
13
- if (update.kind === "remove") return;
14
- if (update.agent.workspaceId != null && update.agent.workspaceId !== workspaceId) return;
15
- if (update.agent.workspaceId == null) return;
16
- }
17
- // cancelQueries cancels synchronously, even when the SDK ignores AbortSignal.
18
- // Restore our captured latest cache after cancellation reverts the old fetch.
19
- void queryClient.cancelQueries({ queryKey, exact: true });
20
- const next = { ...previous };
21
- applyAgentStatusUpdate(next, workspaceId, update);
22
- queryClient.setQueryData(queryKey, next);
23
- }