@koinzhang/paseo-plugin-activity 0.1.0 → 0.3.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 (60) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +85 -0
  3. package/client/activity-heatmap.tsx +72 -14
  4. package/client/formatted-time.tsx +23 -0
  5. package/client/global-surface.tsx +24 -25
  6. package/client/hidden-pill-recheck.test.ts +33 -0
  7. package/client/hidden-pill-recheck.ts +22 -0
  8. package/client/panel.tsx +116 -107
  9. package/client/pill-directory.test.ts +92 -0
  10. package/client/pill-directory.ts +79 -0
  11. package/client/pill.tsx +23 -23
  12. package/client/range.ts +20 -0
  13. package/client/usage-popover.tsx +75 -84
  14. package/client/usage-query.tsx +8 -3
  15. package/client/usage-stats.tsx +7 -5
  16. package/client/use-agent-turn-end.ts +69 -0
  17. package/client/workspace/agent-row.tsx +167 -0
  18. package/client/workspace/agents-section.tsx +330 -0
  19. package/client/workspace/constants.ts +147 -0
  20. package/client/workspace/display-menu.tsx +116 -0
  21. package/client/workspace/filters.ts +30 -0
  22. package/client/workspace/list-host-agents.test.ts +45 -0
  23. package/client/workspace/list-host-agents.ts +90 -0
  24. package/client/workspace/panel.tsx +964 -0
  25. package/client/workspace/rank-section.tsx +131 -0
  26. package/client/workspace/running-indicator.tsx +54 -0
  27. package/client/workspace/status-cache.test.ts +62 -0
  28. package/client/workspace/status-cache.ts +19 -0
  29. package/client/workspace/terminal-preview.test.ts +17 -0
  30. package/client/workspace/terminal-preview.ts +10 -0
  31. package/client/workspace/terminals-section.tsx +155 -0
  32. package/client/workspace-panel.tsx +2 -0
  33. package/index.client.tsx +20 -13
  34. package/index.server.ts +13 -0
  35. package/package.json +9 -3
  36. package/server/agents.test.ts +36 -1
  37. package/server/agents.ts +9 -5
  38. package/server/background-sync.test.ts +14 -3
  39. package/server/background-sync.ts +16 -5
  40. package/server/handlers-query.test.ts +82 -3
  41. package/server/handlers.ts +89 -6
  42. package/server/messages.test.ts +8 -2
  43. package/server/skill-path.ts +3 -20
  44. package/server/store.test.ts +13 -0
  45. package/server/store.ts +2 -2
  46. package/shared/activity.test.ts +22 -12
  47. package/shared/activity.ts +8 -13
  48. package/shared/agent-page-size.test.ts +11 -0
  49. package/shared/agent-title-search.test.ts +28 -0
  50. package/shared/agent-title-search.ts +12 -0
  51. package/shared/explorer-agent-display.ts +30 -0
  52. package/shared/format.test.ts +41 -16
  53. package/shared/format.ts +26 -17
  54. package/shared/home-path.ts +19 -0
  55. package/shared/insights.test.ts +38 -18
  56. package/shared/insights.ts +38 -19
  57. package/shared/list-agent-pages.test.ts +51 -0
  58. package/shared/list-agent-pages.ts +31 -0
  59. package/shared/usage.test.ts +248 -0
  60. package/shared/usage.ts +336 -11
package/server/agents.ts CHANGED
@@ -29,8 +29,10 @@ export function agentRowFromSnapshot(agent: {
29
29
  provider: string;
30
30
  title?: string | null;
31
31
  createdAt: string;
32
+ updatedAt?: string;
33
+ archivedAt?: string | null;
32
34
  }): AgentRow {
33
- const updatedAt = nowIso();
35
+ const updatedAt = agent.updatedAt ?? agent.createdAt;
34
36
  return {
35
37
  agentId: agent.id,
36
38
  workspaceId: agent.workspaceId ?? null,
@@ -38,7 +40,7 @@ export function agentRowFromSnapshot(agent: {
38
40
  provider: agent.provider,
39
41
  title: agent.title ?? null,
40
42
  createdAt: agent.createdAt,
41
- archivedAt: null,
43
+ archivedAt: agent.archivedAt ?? null,
42
44
  updatedAt,
43
45
  };
44
46
  }
@@ -47,7 +49,7 @@ export function agentRowFromSnapshot(agent: {
47
49
  export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
48
50
  const earliest = new Map<
49
51
  string,
50
- { provider: string; workspaceId: string | null; createdAt: string }
52
+ { provider: string; workspaceId: string | null; createdAt: string; updatedAt: string }
51
53
  >();
52
54
  for (const row of rows) {
53
55
  const t = row.ts ?? row.ingestedAt;
@@ -57,10 +59,12 @@ export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
57
59
  provider: row.provider,
58
60
  workspaceId: row.workspaceId,
59
61
  createdAt: t,
62
+ updatedAt: prev && prev.updatedAt > t ? prev.updatedAt : t,
60
63
  });
64
+ } else if (t > prev.updatedAt) {
65
+ prev.updatedAt = t;
61
66
  }
62
67
  }
63
- const updatedAt = nowIso();
64
68
  return [...earliest.entries()].map(([agentId, info]) => ({
65
69
  agentId,
66
70
  workspaceId: info.workspaceId,
@@ -69,7 +73,7 @@ export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
69
73
  title: null,
70
74
  createdAt: info.createdAt,
71
75
  archivedAt: null,
72
- updatedAt,
76
+ updatedAt: info.updatedAt,
73
77
  }));
74
78
  }
75
79
 
@@ -14,7 +14,14 @@ function fixture() {
14
14
  const store = createUsageStore({ dir, driver: "sqlite" });
15
15
  const path = join(dir, "checkpoints.json");
16
16
  const agent = { id: "a1", provider: "codex", createdAt: "2026-09-19", updatedAt: "2026-09-19", lastUserMessageAt: null };
17
- const paseo = { agents: { list: async () => ({ entries: [{ agent }] }) } } as unknown as PaseoApi;
17
+ const paseo = {
18
+ agents: {
19
+ list: async () => ({
20
+ entries: [{ agent }],
21
+ pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
22
+ }),
23
+ },
24
+ } as unknown as PaseoApi;
18
25
  return { store, path, agent, paseo, cleanup() { store.close(); rmSync(dir, { recursive: true, force: true }); } };
19
26
  }
20
27
 
@@ -62,7 +69,8 @@ test("concurrent triggers share one scan; stopping prevents completion checkpoin
62
69
  try {
63
70
  const first = sync.request(f.paseo);
64
71
  assert.equal(sync.request(f.paseo), first);
65
- await Promise.resolve();
72
+ // listAllAgentPages awaits agents.list before scan starts — drain microtasks.
73
+ for (let i = 0; i < 20 && scans === 0; i++) await Promise.resolve();
66
74
  assert.equal(scans, 1);
67
75
  sync.stop(); release(); await first;
68
76
  assert.equal(existsSync(f.path), false);
@@ -121,7 +129,10 @@ test("stopping after agents.list prevents directory writes", async () => {
121
129
  agents: {
122
130
  list: async () => {
123
131
  await listGate;
124
- return { entries: [{ agent: f.agent }] };
132
+ return {
133
+ entries: [{ agent: f.agent }],
134
+ pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
135
+ };
125
136
  },
126
137
  },
127
138
  } as unknown as PaseoApi;
@@ -2,6 +2,7 @@ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import type { PluginHandlerContext } from "@getpaseo/plugin/server";
4
4
  import { LOG_PREFIX } from "../shared/plugin-id.ts";
5
+ import { listAllAgentPages } from "../shared/list-agent-pages.ts";
5
6
  import type { UsageStore } from "./store.ts";
6
7
  import { defaultDataDir } from "./store.ts";
7
8
  import { agentRowFromSnapshot, agentsFromToolCalls } from "./agents.ts";
@@ -12,6 +13,16 @@ type PaseoApi = PluginHandlerContext["paseo"];
12
13
  // Bump when historical ingestion semantics change, not on UI-only releases.
13
14
  const BACKFILL_VERSION = 1;
14
15
  const CHECK_INTERVAL_MS = 5 * 60_000;
16
+ const AGENT_LIST_PAGE_LIMIT = 200;
17
+
18
+ async function listAllAgents(paseo: PaseoApi) {
19
+ return listAllAgentPages(async (cursor) => {
20
+ const result = await paseo.agents.list({
21
+ page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
22
+ });
23
+ return { entries: result.entries, pageInfo: result.pageInfo };
24
+ });
25
+ }
15
26
 
16
27
  export function createBackgroundSync(store: UsageStore, options: {
17
28
  path?: string;
@@ -45,14 +56,14 @@ export function createBackgroundSync(store: UsageStore, options: {
45
56
  }
46
57
 
47
58
  async function check(paseo: PaseoApi) {
48
- const listed = await paseo.agents.list();
59
+ const listedEntries = await listAllAgents(paseo);
49
60
  if (controller.signal.aborted) return;
50
61
  // Directory synchronization belongs to the background task, never a UI read.
51
- store.upsertAgents(listed.entries.map(({ agent }) => agentRowFromSnapshot(agent)));
62
+ store.upsertAgents(listedEntries.map(({ agent }) => agentRowFromSnapshot(agent)));
52
63
  const known = new Set(store.selectAgents().map(agent => agent.agentId));
53
64
  store.upsertAgents(agentsFromToolCalls(store.select()).filter(agent => !known.has(agent.agentId)));
54
65
 
55
- const liveIds = new Set(listed.entries.map(({ agent }) => agent.id));
66
+ const liveIds = new Set(listedEntries.map(({ agent }) => agent.id));
56
67
  const pruned: Record<string, string> = Object.create(null);
57
68
  for (const [id, stamp] of Object.entries(checkpoints)) {
58
69
  if (liveIds.has(id)) pruned[id] = stamp;
@@ -61,11 +72,11 @@ export function createBackgroundSync(store: UsageStore, options: {
61
72
  persistCheckpoints(pruned);
62
73
  }
63
74
 
64
- for (const { agent } of listed.entries) {
75
+ for (const { agent } of listedEntries) {
65
76
  if (controller.signal.aborted) return;
66
77
  const stamp = `${agent.updatedAt}:${agent.lastUserMessageAt ?? ""}`;
67
78
  if (checkpoints[agent.id] === stamp) continue;
68
- const result = await scan(store, paseo, [agent.id], controller.signal, listed.entries);
79
+ const result = await scan(store, paseo, [agent.id], controller.signal, listedEntries);
69
80
  if (controller.signal.aborted) return;
70
81
  if (result.errors.length || result.syncedAgents !== 1) {
71
82
  console.error("[activity] background history scan incomplete", agent.id, result.errors);
@@ -1,11 +1,12 @@
1
1
  import assert from "node:assert/strict";
2
- import { mkdtempSync, rmSync } from "node:fs";
2
+ import { mkdirSync, mkdtempSync, rmSync, 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
8
  createActivityByDayHandler,
9
+ createAgentsHandler,
9
10
  createByProviderHandler,
10
11
  createSkillsByNameHandler,
11
12
  } from "./handlers.ts";
@@ -65,7 +66,64 @@ test("by-provider and activity-by-day read the local store only", async () => {
65
66
  }
66
67
  });
67
68
 
68
- test("skills-by-name never awaits agent.refresh", async () => {
69
+ test("usage.agents filters by workspace and merges the registry", async () => {
70
+ const dir = mkdtempSync(join(tmpdir(), "fast-agents-"));
71
+ const store = createUsageStore({ dir, driver: "sqlite" });
72
+ try {
73
+ store.upsertMany([
74
+ row({ agentId: "a1", callId: "c1", workspaceId: "w1" }),
75
+ row({ agentId: "a2", callId: "c2", workspaceId: "w2" }),
76
+ ]);
77
+ store.upsertAgents([
78
+ {
79
+ agentId: "a1",
80
+ workspaceId: "w1",
81
+ parentAgentId: null,
82
+ provider: "codex",
83
+ title: "Alpha",
84
+ createdAt: "2026-09-19T10:00:00.000Z",
85
+ archivedAt: null,
86
+ updatedAt: "2026-09-19T10:00:00.000Z",
87
+ },
88
+ {
89
+ agentId: "a2",
90
+ workspaceId: "w2",
91
+ parentAgentId: null,
92
+ provider: "codex",
93
+ title: "Beta",
94
+ createdAt: "2026-09-19T10:00:00.000Z",
95
+ archivedAt: null,
96
+ updatedAt: "2026-09-19T10:00:00.000Z",
97
+ },
98
+ {
99
+ agentId: "a3",
100
+ workspaceId: "w1",
101
+ parentAgentId: null,
102
+ provider: "codex",
103
+ title: "Archived",
104
+ createdAt: "2026-09-19T09:00:00.000Z",
105
+ archivedAt: "2026-09-19T11:00:00.000Z",
106
+ updatedAt: "2026-09-19T11:00:00.000Z",
107
+ },
108
+ ]);
109
+ const result = await createAgentsHandler(store)({ workspaceId: "w1" });
110
+ assert.deepEqual(
111
+ result.items.map((item) => item.agentId),
112
+ ["a1", "a3"],
113
+ );
114
+ assert.equal(result.items[0]?.title, "Alpha");
115
+ assert.equal(result.items[0]?.callCount, 1);
116
+ assert.equal(result.items[0]?.skillCalls, 1);
117
+ assert.equal(result.items[0]?.archivedAt, null);
118
+ assert.equal(result.items[0]?.updatedAt, "2026-09-19T10:00:00.000Z");
119
+ assert.equal(result.items[1]?.archivedAt, "2026-09-19T11:00:00.000Z");
120
+ } finally {
121
+ store.close();
122
+ rmSync(dir, { recursive: true, force: true });
123
+ }
124
+ });
125
+
126
+ test("skills-by-name refreshes an empty handle and resolves project skills", async () => {
69
127
  const dir = mkdtempSync(join(tmpdir(), "fast-skills-"));
70
128
  const store = createUsageStore({ dir, driver: "sqlite" });
71
129
  let refreshed = 0;
@@ -75,15 +133,36 @@ test("skills-by-name never awaits agent.refresh", async () => {
75
133
  current: () => null,
76
134
  refresh: async () => {
77
135
  refreshed += 1;
136
+ return { agent: { id: "a1", provider: "codex", cwd: dir } };
78
137
  },
79
138
  }),
80
139
  },
81
140
  } as unknown as PaseoApi;
141
+ try {
142
+ mkdirSync(join(dir, ".claude/skills/demo"), { recursive: true });
143
+ writeFileSync(join(dir, ".claude/skills/demo/SKILL.md"), "# Demo");
144
+ store.upsertMany([row()]);
145
+ const result = await createSkillsByNameHandler(store)({ agentId: "a1" }, { paseo });
146
+ assert.equal(result.items[0]?.skillName, "demo");
147
+ assert.equal(refreshed, 1);
148
+ assert.equal(result.items[0]?.skillPath, join(dir, ".claude/skills/demo/SKILL.md"));
149
+ } finally {
150
+ store.close();
151
+ rmSync(dir, { recursive: true, force: true });
152
+ }
153
+ });
154
+
155
+ test("skills-by-name keeps counts when agent metadata is unavailable", async () => {
156
+ const dir = mkdtempSync(join(tmpdir(), "missing-agent-"));
157
+ const store = createUsageStore({ dir, driver: "sqlite" });
158
+ const paseo = { agents: { ref: () => ({
159
+ current: () => null,
160
+ refresh: async () => null,
161
+ }) } } as unknown as PaseoApi;
82
162
  try {
83
163
  store.upsertMany([row()]);
84
164
  const result = await createSkillsByNameHandler(store)({ agentId: "a1" }, { paseo });
85
165
  assert.equal(result.items[0]?.skillName, "demo");
86
- assert.equal(refreshed, 0);
87
166
  } finally {
88
167
  store.close();
89
168
  rmSync(dir, { recursive: true, force: true });
@@ -5,6 +5,7 @@ import { homedir } from "node:os";
5
5
  import { basename, dirname, resolve, sep } from "node:path";
6
6
  import { realpathSync, statSync } from "node:fs";
7
7
  import {
8
+ aggregateAgents,
8
9
  aggregateByProvider,
9
10
  aggregateMcpByTool,
10
11
  aggregateShellTop,
@@ -14,6 +15,8 @@ import {
14
15
  isFileWrite,
15
16
  isShellCall,
16
17
  usageActivityByDayRpc,
18
+ usageAgentsRpc,
19
+ usageAgentUnarchiveRpc,
17
20
  usageByProviderRpc,
18
21
  usageExportRpc,
19
22
  usageListRpc,
@@ -22,6 +25,7 @@ import {
22
25
  usageSkillsByNameRpc,
23
26
  usageSummaryRpc,
24
27
  } from "../shared/usage.ts";
28
+ import { listAllAgentPages } from "../shared/list-agent-pages.ts";
25
29
  import { DEFAULT_SKILL_ROOTS, matchSkillFile } from "../shared/classify.ts";
26
30
  import { buildHomeSkillRoots, buildSkillRoots, toolCallToRow, ingestUserMessages } from "./ingest.ts";
27
31
  import { normalizeModelId } from "./resolve-model.ts";
@@ -36,6 +40,12 @@ import { formatLocalDateTime } from "../shared/format.ts";
36
40
  import { agentRowFromSnapshot } from "./agents.ts";
37
41
  import { readFile } from "node:fs/promises";
38
42
 
43
+ const AGENT_LIST_PAGE_LIMIT = 200;
44
+ import { execFile } from "node:child_process";
45
+ import { promisify } from "node:util";
46
+
47
+ const execFileAsync = promisify(execFile);
48
+
39
49
  type PaseoApi = PluginHandlerContext["paseo"];
40
50
 
41
51
  export type UsageSummary = RpcOutput<typeof usageSummaryRpc>;
@@ -82,6 +92,7 @@ export function summarizeRows(rows: readonly ToolCallRow[]): UsageSummary {
82
92
  mcpCalls,
83
93
  mcpFailures,
84
94
  toolCallsByKind,
95
+ messageCount: 0,
85
96
  };
86
97
  }
87
98
 
@@ -93,7 +104,10 @@ export function createSummaryHandler(store: UsageStore) {
93
104
  from: input.from,
94
105
  to: input.to,
95
106
  };
96
- return summarizeRows(store.select(filter));
107
+ return {
108
+ ...summarizeRows(store.select(filter)),
109
+ messageCount: store.selectUserMessages(filter).length,
110
+ };
97
111
  };
98
112
  }
99
113
 
@@ -137,14 +151,21 @@ export function createListHandler(store: UsageStore) {
137
151
  };
138
152
  }
139
153
 
140
- function skillRootsForQuery(
154
+ async function skillRootsForQuery(
141
155
  paseo: PaseoApi,
142
156
  agentId: string | undefined,
143
157
  homeDir: string,
144
- ): string[] {
158
+ ): Promise<string[]> {
145
159
  if (!agentId) return buildHomeSkillRoots(homeDir);
146
160
  const handle = paseo.agents.ref(agentId);
147
- const snapshot = handle.current();
161
+ let snapshot = handle.current();
162
+ if (!snapshot) {
163
+ try {
164
+ snapshot = (await handle.refresh())?.agent ?? handle.current();
165
+ } catch (error) {
166
+ console.error("[activity] could not resolve agent skill roots", error);
167
+ }
168
+ }
148
169
  if (snapshot?.cwd) {
149
170
  return buildSkillRoots(agentFromSnapshot(snapshot), homeDir);
150
171
  }
@@ -164,7 +185,7 @@ export function createSkillsByNameHandler(store: UsageStore) {
164
185
  from: input.from,
165
186
  to: input.to,
166
187
  });
167
- const roots = skillRootsForQuery(context.paseo, input.agentId, homeDir);
188
+ const roots = await skillRootsForQuery(context.paseo, input.agentId, homeDir);
168
189
  const items = finalizeSkillPaths(aggregateSkillsByName(rows), roots, homeDir);
169
190
  return { items };
170
191
  };
@@ -213,6 +234,61 @@ export function createByProviderHandler(store: UsageStore) {
213
234
  };
214
235
  }
215
236
 
237
+ export function createAgentsHandler(store: UsageStore) {
238
+ return async (
239
+ input: RpcInput<typeof usageAgentsRpc>,
240
+ ): Promise<RpcOutput<typeof usageAgentsRpc>> => {
241
+ const rows = store.select({
242
+ workspaceId: input.workspaceId,
243
+ from: input.from,
244
+ to: input.to,
245
+ });
246
+ // Registry lookup ignores the window so titles stay available for agents
247
+ // created before it; activity counts still come from the filtered rows.
248
+ const agents = store.selectAgents({ workspaceId: input.workspaceId });
249
+ const messages = store.selectUserMessages({
250
+ workspaceId: input.workspaceId,
251
+ from: input.from,
252
+ to: input.to,
253
+ });
254
+ return { items: aggregateAgents(rows, agents, messages) };
255
+ };
256
+ }
257
+
258
+ /**
259
+ * 0.8 SDK has no reload API (handle.refresh is a read). Run CLI on this daemon's
260
+ * machine, inheriting PATH and PASEO_HOME / PASEO_HOST / PASEO_LISTEN. CLI also
261
+ * resolves its pid/config socket. Requires that environment to target this daemon;
262
+ * do not substitute the client UI's remote host or hard-code a default port.
263
+ */
264
+ export function createUnarchiveAgentHandler(store: UsageStore) {
265
+ return async (
266
+ input: RpcInput<typeof usageAgentUnarchiveRpc>,
267
+ ): Promise<RpcOutput<typeof usageAgentUnarchiveRpc>> => {
268
+ try {
269
+ await execFileAsync("paseo", ["agent", "reload", input.agentId], {
270
+ timeout: 120_000,
271
+ maxBuffer: 1024 * 1024,
272
+ });
273
+ } catch (error) {
274
+ const err = error as { stderr?: string; message?: string };
275
+ const detail = (err.stderr?.trim() || err.message || String(error)).trim();
276
+ throw new Error(detail || `Failed to unarchive agent ${input.agentId}`);
277
+ }
278
+ const existing = store.getAgent(input.agentId);
279
+ if (existing) {
280
+ store.upsertAgents([
281
+ {
282
+ ...existing,
283
+ archivedAt: null,
284
+ updatedAt: new Date().toISOString(),
285
+ },
286
+ ]);
287
+ }
288
+ return { agentId: input.agentId, ok: true };
289
+ };
290
+ }
291
+
216
292
  export function createActivityByDayHandler(store: UsageStore) {
217
293
  return async (
218
294
  input: RpcInput<typeof usageActivityByDayRpc>,
@@ -456,7 +532,14 @@ export async function resyncAgents(
456
532
  const homeDir = homedir();
457
533
  const listed = listedEntries
458
534
  ? { entries: listedEntries }
459
- : await paseo.agents.list();
535
+ : {
536
+ entries: await listAllAgentPages(async (cursor) => {
537
+ const result = await paseo.agents.list({
538
+ page: { limit: AGENT_LIST_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
539
+ });
540
+ return { entries: result.entries, pageInfo: result.pageInfo };
541
+ }),
542
+ };
460
543
  const targets = listed.entries
461
544
  .map((entry) => entry.agent)
462
545
  .filter((agent) => !agentIds || agentIds.includes(agent.id));
@@ -96,7 +96,10 @@ test("resync paginates messages idempotently; query handlers use stored messages
96
96
  const store = createUsageStore({ dir, driver: "sqlite" });
97
97
  let calls = 0;
98
98
  const paseo = { agents: {
99
- list: async () => ({ entries: [{ agent: { ...agent, createdAt: earlier } }] }),
99
+ list: async () => ({
100
+ entries: [{ agent: { ...agent, createdAt: earlier } }],
101
+ pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
102
+ }),
100
103
  ref: () => ({ timeline: { refetch: async (input: { direction: string }) => {
101
104
  calls++;
102
105
  const tail = input.direction === "tail";
@@ -132,7 +135,10 @@ test("canceling an in-flight canonical scan prevents writes after the store clos
132
135
  const started = new Promise<void>(resolve => { entered = resolve; });
133
136
  const gate = new Promise<void>(resolve => { release = resolve; });
134
137
  const paseo = { agents: {
135
- list: async () => ({ entries: [{ agent: { ...agent, createdAt: earlier } }] }),
138
+ list: async () => ({
139
+ entries: [{ agent: { ...agent, createdAt: earlier } }],
140
+ pageInfo: { hasMore: false, nextCursor: null, prevCursor: null },
141
+ }),
136
142
  ref: () => ({ timeline: { refetch: async () => {
137
143
  entered(); await gate;
138
144
  return { entries: [{ item: message, timestamp: earlier, seqStart: 1 }], hasOlder: false,
@@ -1,7 +1,10 @@
1
1
  import { existsSync, readdirSync } from "node:fs";
2
2
  import { join } from "node:path";
3
+ import { collapseHomePath } from "../shared/home-path.ts";
3
4
  import { createKeyedTtlCache } from "./ttl-cache.ts";
4
5
 
6
+ export { collapseHomePath };
7
+
5
8
  /** Expand a leading `~` / `~/…` to an absolute path under `homeDir`. */
6
9
  export function expandHomePath(path: string, homeDir: string): string {
7
10
  const trimmed = path.trim();
@@ -10,26 +13,6 @@ export function expandHomePath(path: string, homeDir: string): string {
10
13
  return trimmed;
11
14
  }
12
15
 
13
- /** Collapse `homeDir` prefix to `~` so RPC/UI never expose `/Users/…`. */
14
- export function collapseHomePath(path: string, homeDir: string): string {
15
- const trimmed = path.trim();
16
- if (!trimmed || !homeDir) return trimmed;
17
- if (trimmed === homeDir) return "~";
18
- const prefix = homeDir.endsWith("/") ? homeDir : `${homeDir}/`;
19
- if (trimmed.startsWith(prefix)) {
20
- return `~/${trimmed.slice(prefix.length)}`;
21
- }
22
- // Case-insensitive match (macOS default FS); preserve the remainder as-is.
23
- const lower = trimmed.toLowerCase();
24
- const homeLower = homeDir.toLowerCase();
25
- if (lower === homeLower) return "~";
26
- const prefixLower = homeLower.endsWith("/") ? homeLower : `${homeLower}/`;
27
- if (lower.startsWith(prefixLower)) {
28
- return `~/${trimmed.slice(prefixLower.length)}`;
29
- }
30
- return trimmed;
31
- }
32
-
33
16
  const rootListingCache = createKeyedTtlCache<string[]>(30_000);
34
17
 
35
18
  function listRootEntries(root: string): string[] {
@@ -148,6 +148,19 @@ test("sqlite: upsertAgents keeps earliest createdAt and sets archivedAt", () =>
148
148
  assert.equal(agent?.archivedAt, "2026-09-20T00:00:00.000Z");
149
149
  assert.equal(agent?.title, "One renamed");
150
150
  assert.equal(store.selectAgents({ from: "2026-09-18T00:00:00.000Z" }).length, 1);
151
+ store.upsertAgents([
152
+ {
153
+ agentId: "a1",
154
+ workspaceId: "w1",
155
+ parentAgentId: null,
156
+ provider: "claude",
157
+ title: "One renamed",
158
+ createdAt: "2026-09-19T12:00:00.000Z",
159
+ archivedAt: null,
160
+ updatedAt: "2026-09-20T01:00:00.000Z",
161
+ },
162
+ ]);
163
+ assert.equal(store.getAgent("a1")?.archivedAt, null);
151
164
  store.close();
152
165
  });
153
166
 
package/server/store.ts CHANGED
@@ -360,7 +360,7 @@ export function mergeAgentRow(previous: AgentRow, next: AgentRow): AgentRow {
360
360
  provider: next.provider || previous.provider,
361
361
  title: next.title ?? previous.title,
362
362
  createdAt: previous.createdAt <= next.createdAt ? previous.createdAt : next.createdAt,
363
- archivedAt: next.archivedAt ?? previous.archivedAt,
363
+ archivedAt: next.archivedAt,
364
364
  updatedAt: next.updatedAt >= previous.updatedAt ? next.updatedAt : previous.updatedAt,
365
365
  };
366
366
  }
@@ -431,7 +431,7 @@ ON CONFLICT(agent_id) DO UPDATE SET
431
431
  WHEN excluded.created_at < agents.created_at THEN excluded.created_at
432
432
  ELSE agents.created_at
433
433
  END,
434
- archived_at = COALESCE(excluded.archived_at, agents.archived_at),
434
+ archived_at = excluded.archived_at,
435
435
  updated_at = excluded.updated_at
436
436
  `;
437
437
 
@@ -13,9 +13,9 @@ describe("activity calendar", () => {
13
13
  it("formats months with the explicit app language", () => {
14
14
  const english = buildActivityCalendar([], "daily", from, today, "en");
15
15
  const chinese = buildActivityCalendar([], "daily", from, today, "zh-CN");
16
- assert.equal(english.months.length, 1);
17
- assert.equal(english.months[0]?.label, "Mar");
18
- assert.equal(chinese.months[0]?.label, "3月");
16
+ assert.equal(english.months.length, 12);
17
+ assert.equal(english.months[11]?.label, "Mar");
18
+ assert.equal(chinese.months[11]?.label, "3月");
19
19
  });
20
20
  it("uses 12 evenly spaced month labels for a year window", () => {
21
21
  const result = buildActivityCalendar([], "daily", undefined, new Date(2026, 8, 19), "en");
@@ -37,6 +37,14 @@ describe("activity calendar", () => {
37
37
  }
38
38
  }
39
39
  });
40
+ it("keeps 52-week layout even when a short range from is passed (021)", () => {
41
+ const short = buildActivityCalendar([], "daily", from, today, "en");
42
+ const all = buildActivityCalendar([], "daily", undefined, today, "en");
43
+ assert.equal(short.weeks.length, 52);
44
+ assert.equal(short.months.length, 12);
45
+ assert.equal(short.weeks.length, all.weeks.length);
46
+ assert.equal(short.months.length, all.months.length);
47
+ });
40
48
  it("carries cumulative counts across missing days including today", () => {
41
49
  const cells = buildActivityCalendar(days, "cumulative", from, today).weeks.flat();
42
50
  assert.equal(cells.find(c => c.key === "2026-03-08")?.total, 9);
@@ -47,23 +55,25 @@ describe("activity calendar", () => {
47
55
  });
48
56
  it("keeps daily gaps empty and aggregates Sunday-start weeks", () => {
49
57
  assert.equal(buildActivityCalendar(days, "daily", from, today).weeks.flat().find(c => c.key === "2026-03-08")?.total, 0);
50
- const weekly = buildActivityCalendar(days, "weekly", from, today).weeks[1]?.[0];
51
- assert.equal(weekly?.total, 9);
52
- assert.equal(weekly?.agents, 1);
53
- assert.equal(weekly?.messages, 3);
58
+ const weekStart = "2026-03-08"; // Sunday containing 2026-03-09
59
+ const weeklyCell = buildActivityCalendar(days, "weekly", from, today)
60
+ .weeks.flat()
61
+ .find((c) => c.key === weekStart);
62
+ assert.equal(weeklyCell?.total, 9);
63
+ assert.equal(weeklyCell?.agents, 1);
64
+ assert.equal(weeklyCell?.messages, 3);
54
65
  });
55
- it("includes the current week across DST and marks padding cells", () => {
66
+ it("includes the current week across DST and marks future padding cells", () => {
56
67
  const previous = process.env.TZ;
57
68
  process.env.TZ = "America/New_York";
58
69
  try {
59
70
  const result = buildActivityCalendar([], "daily", new Date(2026, 2, 1).toISOString(), new Date(2026, 2, 15));
60
- assert.equal(result.weeks.length, 3);
61
- assert.equal(result.weeks[2]?.[0]?.key, "2026-03-15");
62
- assert.equal(result.weeks[2]?.[1]?.future, true);
71
+ assert.equal(result.weeks.length, 52);
72
+ assert.equal(result.weeks[51]?.[0]?.key, "2026-03-15");
73
+ assert.equal(result.weeks[51]?.[1]?.future, true);
63
74
  } finally {
64
75
  if (previous === undefined) delete process.env.TZ; else process.env.TZ = previous;
65
76
  }
66
- assert.equal(buildActivityCalendar([], "daily", from, today).weeks[0]?.[0]?.excluded, true);
67
77
  });
68
78
  it("renders empty windows and bounded intensity", () => {
69
79
  const result = buildActivityCalendar([], "daily", undefined, today);
@@ -32,19 +32,12 @@ function addDays(date: Date, days: number): Date {
32
32
 
33
33
  export type HeatmapMode = "daily" | "weekly" | "cumulative";
34
34
 
35
- export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, from?: string, today = new Date(), locale = "en") {
35
+ export function buildActivityCalendar(days: readonly ActivityDay[], mode: HeatmapMode, _from?: string, today = new Date(), locale = "en") {
36
36
  const end = startOfLocalDay(today);
37
- let first: Date;
38
- let start: Date;
39
- if (from) {
40
- const parsed = startOfLocalDay(new Date(from));
41
- first = Number.isNaN(parsed.getTime()) ? addDays(end, -363) : parsed;
42
- start = startOfWeekSunday(first);
43
- } else {
44
- // Fixed 52-week year window (ChatGPT-style): current week + 51 prior weeks.
45
- start = addDays(startOfWeekSunday(end), -7 * 51);
46
- first = start;
47
- }
37
+ // Always fixed 52-week year window (ChatGPT-style). Range chips filter RPC data only —
38
+ // short windows must not shrink the grid (021). `_from` kept for call-site compatibility.
39
+ const start = addDays(startOfWeekSunday(end), -7 * 51);
40
+ const first = start;
48
41
  const daily = new Map(days.map(day => [day.date, day]));
49
42
  const weekly = new Map<string, ActivityDay>();
50
43
  for (const day of days) {
@@ -126,7 +119,7 @@ export function buildActivityCalendar(days: readonly ActivityDay[], mode: Heatma
126
119
  (endMonth.getMonth() - startMonth.getMonth()) +
127
120
  1;
128
121
  const monthCount = Math.min(12, Math.max(1, spanMonths));
129
- const months: Array<{ index: number; label: string }> = [];
122
+ const months: Array<{ index: number; label: string; year: number; month: number }> = [];
130
123
  for (let i = 0; i < monthCount; i++) {
131
124
  const date =
132
125
  monthCount === 12
@@ -135,6 +128,8 @@ export function buildActivityCalendar(days: readonly ActivityDay[], mode: Heatma
135
128
  months.push({
136
129
  index: (i / monthCount) * weeks.length,
137
130
  label: date.toLocaleDateString(locale, { month: "short" }),
131
+ year: date.getFullYear(),
132
+ month: date.getMonth(),
138
133
  });
139
134
  }
140
135
  return { weeks, months, max };
@@ -0,0 +1,11 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { AGENT_PAGE_SIZE } from "../client/workspace/constants.ts";
4
+
5
+ test("AGENT_PAGE_SIZE yields single page for ≤ page size", () => {
6
+ assert.ok(AGENT_PAGE_SIZE > 0);
7
+ const pageCount = (n: number) => Math.max(1, Math.ceil(n / AGENT_PAGE_SIZE));
8
+ assert.equal(pageCount(0), 1);
9
+ assert.equal(pageCount(AGENT_PAGE_SIZE), 1);
10
+ assert.equal(pageCount(AGENT_PAGE_SIZE + 1), 2);
11
+ });