@koinzhang/paseo-plugin-activity 0.2.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 (38) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +23 -9
  3. package/client/formatted-time.tsx +23 -0
  4. package/client/hidden-pill-recheck.test.ts +33 -0
  5. package/client/hidden-pill-recheck.ts +22 -0
  6. package/client/panel.tsx +115 -107
  7. package/client/pill-directory.test.ts +92 -0
  8. package/client/pill-directory.ts +79 -0
  9. package/client/pill.tsx +23 -23
  10. package/client/usage-popover.tsx +75 -84
  11. package/client/usage-query.tsx +8 -3
  12. package/client/usage-stats.tsx +2 -2
  13. package/client/use-agent-turn-end.ts +69 -0
  14. package/client/workspace/agent-row.tsx +57 -7
  15. package/client/workspace/agents-section.tsx +7 -0
  16. package/client/workspace/constants.ts +29 -3
  17. package/client/workspace/filters.ts +2 -2
  18. package/client/workspace/list-host-agents.test.ts +45 -0
  19. package/client/workspace/list-host-agents.ts +55 -22
  20. package/client/workspace/panel.tsx +172 -8
  21. package/client/workspace/rank-section.tsx +36 -26
  22. package/client/workspace/running-indicator.tsx +54 -0
  23. package/client/workspace/status-cache.test.ts +62 -0
  24. package/client/workspace/status-cache.ts +19 -0
  25. package/client/workspace/terminal-preview.test.ts +17 -0
  26. package/client/workspace/terminal-preview.ts +10 -0
  27. package/client/workspace/terminals-section.tsx +155 -0
  28. package/index.server.ts +2 -0
  29. package/package.json +3 -3
  30. package/server/agents.test.ts +16 -0
  31. package/server/agents.ts +7 -4
  32. package/server/handlers-query.test.ts +24 -3
  33. package/server/handlers.ts +17 -5
  34. package/server/skill-path.ts +3 -20
  35. package/shared/format.test.ts +35 -31
  36. package/shared/format.ts +21 -36
  37. package/shared/home-path.ts +19 -0
  38. package/shared/usage.ts +9 -0
@@ -0,0 +1,54 @@
1
+ import { useEffect, useRef, type ReactNode } from "react";
2
+ import { Animated, Easing, type ViewStyle } from "react-native";
3
+ import type { WorkspaceTheme } from "./constants.ts";
4
+
5
+ const SPIN_SIZE = 10;
6
+ const SPIN_DURATION_MS = 800;
7
+
8
+ /** Host-style running ring: border-colored track with an accent arc, rotating. */
9
+ export function RunningIndicator({
10
+ theme,
11
+ style,
12
+ }: {
13
+ theme: WorkspaceTheme;
14
+ style?: ViewStyle;
15
+ }): ReactNode {
16
+ const spin = useRef(new Animated.Value(0)).current;
17
+
18
+ useEffect(() => {
19
+ const animation = Animated.loop(
20
+ Animated.timing(spin, {
21
+ toValue: 1,
22
+ duration: SPIN_DURATION_MS,
23
+ easing: Easing.linear,
24
+ useNativeDriver: false,
25
+ }),
26
+ );
27
+ animation.start();
28
+ return () => animation.stop();
29
+ }, [spin]);
30
+
31
+ return (
32
+ <Animated.View
33
+ style={[
34
+ {
35
+ width: SPIN_SIZE,
36
+ height: SPIN_SIZE,
37
+ borderRadius: SPIN_SIZE / 2,
38
+ borderWidth: 2,
39
+ borderColor: theme.colors.border,
40
+ borderTopColor: theme.colors.accent,
41
+ transform: [
42
+ {
43
+ rotate: spin.interpolate({
44
+ inputRange: [0, 1],
45
+ outputRange: ["0deg", "360deg"],
46
+ }),
47
+ },
48
+ ],
49
+ },
50
+ style,
51
+ ]}
52
+ />
53
+ );
54
+ }
@@ -0,0 +1,62 @@
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 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" }) };
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, undefined);
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" } }], pageInfo: { hasMore: false, nextCursor: null } };
41
+ },
42
+ } }, "w");
43
+ assert.equal(map.a?.permissionCount, 1);
44
+ assert.equal(map.b, undefined);
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
+ });
@@ -0,0 +1,19 @@
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) && (update.kind === "remove" || update.agent.workspaceId !== workspaceId)) return;
13
+ // cancelQueries cancels synchronously, even when the SDK ignores AbortSignal.
14
+ // Restore our captured latest cache after cancellation reverts the old fetch.
15
+ void queryClient.cancelQueries({ queryKey, exact: true });
16
+ const next = { ...previous };
17
+ applyAgentStatusUpdate(next, workspaceId, update);
18
+ queryClient.setQueryData(queryKey, next);
19
+ }
@@ -0,0 +1,17 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { terminalPreviewLines } from "./terminal-preview.ts";
4
+
5
+ test("terminalPreviewLines trims trailing blank lines", () => {
6
+ assert.deepEqual(terminalPreviewLines(["a", "b", "", " "], 10), ["a", "b"]);
7
+ });
8
+
9
+ test("terminalPreviewLines keeps the last max lines", () => {
10
+ assert.deepEqual(terminalPreviewLines(["1", "2", "3", "4"], 2), ["3", "4"]);
11
+ assert.deepEqual(terminalPreviewLines(["1", "2", "3"], 0), []);
12
+ });
13
+
14
+ test("terminalPreviewLines handles empty and blank-only output", () => {
15
+ assert.deepEqual(terminalPreviewLines([], 5), []);
16
+ assert.deepEqual(terminalPreviewLines(["", " "], 5), []);
17
+ });
@@ -0,0 +1,10 @@
1
+ /** Capture output ends with blank rows for a fresh shell; keep the last N meaningful lines. */
2
+ export function terminalPreviewLines(
3
+ lines: ReadonlyArray<string>,
4
+ max: number,
5
+ ): string[] {
6
+ let end = lines.length;
7
+ while (end > 0 && (lines[end - 1] ?? "").trim() === "") end -= 1;
8
+ const start = Math.max(0, end - max);
9
+ return lines.slice(start, end);
10
+ }
@@ -0,0 +1,155 @@
1
+ import { usePaseo } from "@getpaseo/plugin/client";
2
+ import { Icon } from "@getpaseo/plugin/client/react-native";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { useEffect, useState, type ReactNode } from "react";
5
+ import {
6
+ ActivityIndicator,
7
+ Platform,
8
+ Pressable,
9
+ Text,
10
+ View,
11
+ type TextStyle,
12
+ type ViewStyle,
13
+ } from "react-native";
14
+ import { collapseHomePath } from "../../shared/home-path.ts";
15
+ import { TERMINAL_PREVIEW_LINES, TERMINAL_REFETCH_MS } from "./constants.ts";
16
+ import { terminalPreviewLines } from "./terminal-preview.ts";
17
+
18
+ export type TerminalListItem = {
19
+ id: string;
20
+ workspaceId: string;
21
+ cwd: string;
22
+ name: string;
23
+ };
24
+
25
+ export type TerminalsSectionStyles = {
26
+ sectionHeaderRow: ViewStyle;
27
+ sectionTitle: TextStyle;
28
+ panel: ViewStyle;
29
+ terminalRow: ViewStyle;
30
+ listMain: ViewStyle;
31
+ listTitle: TextStyle;
32
+ listMeta: TextStyle;
33
+ titleAction: ViewStyle;
34
+ terminalPreview: ViewStyle;
35
+ terminalLine: TextStyle;
36
+ };
37
+
38
+ export function TerminalsSection({
39
+ workspaceId,
40
+ terminalItems,
41
+ busyTerminalId,
42
+ homeDir,
43
+ mutedColor,
44
+ styles,
45
+ onClose,
46
+ }: {
47
+ workspaceId: string;
48
+ terminalItems: ReadonlyArray<TerminalListItem>;
49
+ busyTerminalId: string | null;
50
+ homeDir?: string;
51
+ mutedColor: string;
52
+ styles: TerminalsSectionStyles;
53
+ onClose: (item: TerminalListItem) => void;
54
+ }): ReactNode {
55
+ const paseo = usePaseo();
56
+ const [expandedId, setExpandedId] = useState<string | null>(null);
57
+ const [hoveredId, setHoveredId] = useState<string | null>(null);
58
+
59
+ useEffect(() => {
60
+ if (expandedId != null && !terminalItems.some((item) => item.id === expandedId)) {
61
+ setExpandedId(null);
62
+ }
63
+ }, [expandedId, terminalItems]);
64
+
65
+ const capture = useQuery({
66
+ enabled: expandedId != null,
67
+ refetchInterval: TERMINAL_REFETCH_MS,
68
+ retry: false,
69
+ queryKey: ["activity", "terminal-capture", workspaceId, expandedId],
70
+ queryFn: async () => {
71
+ const result = await paseo.terminals
72
+ .ref(expandedId as string)
73
+ .capture({ stripAnsi: true });
74
+ return terminalPreviewLines(result.lines, TERMINAL_PREVIEW_LINES);
75
+ },
76
+ });
77
+
78
+ return (
79
+ <View style={{ gap: 12 }}>
80
+ <View style={styles.sectionHeaderRow}>
81
+ <Text style={styles.sectionTitle}>Terminals</Text>
82
+ </View>
83
+ <View style={styles.panel}>
84
+ {terminalItems.map((item) => {
85
+ const expanded = item.id === expandedId;
86
+ const busy = busyTerminalId === item.id;
87
+ // Web: hover-reveal. Native has no hover — keep the action visible.
88
+ const showClose = Platform.OS !== "web" || hoveredId === item.id || busy;
89
+ const lines = expanded ? (capture.data ?? []) : [];
90
+ return (
91
+ <View key={item.id}>
92
+ <Pressable
93
+ accessibilityRole="button"
94
+ accessibilityLabel={
95
+ expanded ? `Hide output of ${item.name}` : `Show output of ${item.name}`
96
+ }
97
+ accessibilityState={{ expanded }}
98
+ onPress={() => setExpandedId(expanded ? null : item.id)}
99
+ style={styles.terminalRow}
100
+ {...(Platform.OS === "web"
101
+ ? ({
102
+ onMouseEnter: () => setHoveredId(item.id),
103
+ onMouseLeave: () =>
104
+ setHoveredId((prev) => (prev === item.id ? null : prev)),
105
+ } as object)
106
+ : null)}
107
+ >
108
+ <Icon name="Terminal" size={18} color={mutedColor} />
109
+ <View style={styles.listMain}>
110
+ <Text style={styles.listTitle} numberOfLines={1}>
111
+ {item.name}
112
+ </Text>
113
+ <Text style={styles.listMeta} numberOfLines={1}>
114
+ {collapseHomePath(item.cwd, homeDir ?? "")}
115
+ </Text>
116
+ </View>
117
+ <Pressable
118
+ accessibilityRole="button"
119
+ accessibilityLabel={`Close ${item.name}`}
120
+ accessibilityState={{ disabled: busyTerminalId != null }}
121
+ disabled={busyTerminalId != null || !showClose}
122
+ hitSlop={8}
123
+ onPress={() => onClose(item)}
124
+ pointerEvents={showClose ? "auto" : "none"}
125
+ style={[styles.titleAction, { opacity: showClose ? 1 : 0 }]}
126
+ >
127
+ {busy ? (
128
+ <ActivityIndicator size="small" color={mutedColor} />
129
+ ) : (
130
+ <Icon name="X" size={14} color={mutedColor} />
131
+ )}
132
+ </Pressable>
133
+ </Pressable>
134
+ {expanded ? (
135
+ <View style={styles.terminalPreview}>
136
+ {capture.isPending ? (
137
+ <Text style={styles.listMeta}>Loading…</Text>
138
+ ) : lines.length === 0 ? (
139
+ <Text style={styles.listMeta}>No output</Text>
140
+ ) : (
141
+ lines.map((line, index) => (
142
+ <Text key={index} style={styles.terminalLine} numberOfLines={1}>
143
+ {line.length > 0 ? line : " "}
144
+ </Text>
145
+ ))
146
+ )}
147
+ </View>
148
+ ) : null}
149
+ </View>
150
+ );
151
+ })}
152
+ </View>
153
+ </View>
154
+ );
155
+ }
package/index.server.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  usageAgentUnarchiveRpc,
24
24
  usageByProviderRpc,
25
25
  usageExportRpc,
26
+ usageHostInfoRpc,
26
27
  usageListRpc,
27
28
  usageMcpByToolRpc,
28
29
  usageReadSkillRpc,
@@ -67,6 +68,7 @@ export default function contribute(server: PluginServerContext) {
67
68
  return createActivityByDayHandler(store)(input);
68
69
  });
69
70
  server.handle(usageExportRpc, createExportHandler(store));
71
+ server.handle(usageHostInfoRpc, () => ({ homeDir: homedir() }));
70
72
  server.handle(usageReadSkillRpc, createReadSkillHandler());
71
73
 
72
74
  const removeCreated = server.on("agent.created", (event, context) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koinzhang/paseo-plugin-activity",
3
- "version": "0.2.0",
4
- "description": "Local usage analytics for Paseo: tool calls, agents, messages, and model usage.",
3
+ "version": "0.3.0",
4
+ "description": "Local usage analytics and workspace agent ops for Paseo: tools, agents, messages, models, Explorer fleet list, and terminals.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "typecheck": "tsc --noEmit",
25
- "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/pill-data-cache.test.ts client/rank-color.test.ts client/provider-filter.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts"
25
+ "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/pill-data-cache.test.ts client/pill-directory.test.ts client/hidden-pill-recheck.test.ts client/workspace/list-host-agents.test.ts client/workspace/status-cache.test.ts client/rank-color.test.ts client/provider-filter.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@getpaseo/plugin": "0.8.0",
@@ -84,3 +84,19 @@ describe("agentRowFromSnapshot", () => {
84
84
  assert.equal(archived.archivedAt, "2026-09-19T00:00:00.000Z");
85
85
  });
86
86
  });
87
+
88
+ describe("agent activity timestamps", () => {
89
+ it("preserves snapshot time and uses creation time only when absent", () => {
90
+ const agent = { id: "a", provider: "codex", createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-02T00:00:00Z" };
91
+ assert.equal(agentRowFromSnapshot(agent).updatedAt, agent.updatedAt);
92
+ assert.equal(agentRowFromSnapshot({ ...agent, updatedAt: undefined }).updatedAt, agent.createdAt);
93
+ });
94
+ it("derives last activity from tool history regardless of input order", () => {
95
+ const calls = [row({ ts: "2026-01-03T00:00:00Z" }), row({ ts: "2026-01-01T00:00:00Z" }), row({ ts: "2026-01-04T00:00:00Z" })];
96
+ for (const ordered of [calls, calls.slice().reverse()]) {
97
+ const agent = agentsFromToolCalls(ordered)[0]!;
98
+ assert.equal(agent.createdAt, "2026-01-01T00:00:00Z");
99
+ assert.equal(agent.updatedAt, "2026-01-04T00:00:00Z");
100
+ }
101
+ });
102
+ });
package/server/agents.ts CHANGED
@@ -29,9 +29,10 @@ export function agentRowFromSnapshot(agent: {
29
29
  provider: string;
30
30
  title?: string | null;
31
31
  createdAt: string;
32
+ updatedAt?: string;
32
33
  archivedAt?: string | null;
33
34
  }): AgentRow {
34
- const updatedAt = nowIso();
35
+ const updatedAt = agent.updatedAt ?? agent.createdAt;
35
36
  return {
36
37
  agentId: agent.id,
37
38
  workspaceId: agent.workspaceId ?? null,
@@ -48,7 +49,7 @@ export function agentRowFromSnapshot(agent: {
48
49
  export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
49
50
  const earliest = new Map<
50
51
  string,
51
- { provider: string; workspaceId: string | null; createdAt: string }
52
+ { provider: string; workspaceId: string | null; createdAt: string; updatedAt: string }
52
53
  >();
53
54
  for (const row of rows) {
54
55
  const t = row.ts ?? row.ingestedAt;
@@ -58,10 +59,12 @@ export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
58
59
  provider: row.provider,
59
60
  workspaceId: row.workspaceId,
60
61
  createdAt: t,
62
+ updatedAt: prev && prev.updatedAt > t ? prev.updatedAt : t,
61
63
  });
64
+ } else if (t > prev.updatedAt) {
65
+ prev.updatedAt = t;
62
66
  }
63
67
  }
64
- const updatedAt = nowIso();
65
68
  return [...earliest.entries()].map(([agentId, info]) => ({
66
69
  agentId,
67
70
  workspaceId: info.workspaceId,
@@ -70,7 +73,7 @@ export function agentsFromToolCalls(rows: readonly ToolCallRow[]): AgentRow[] {
70
73
  title: null,
71
74
  createdAt: info.createdAt,
72
75
  archivedAt: null,
73
- updatedAt,
76
+ updatedAt: info.updatedAt,
74
77
  }));
75
78
  }
76
79
 
@@ -1,5 +1,5 @@
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";
@@ -123,7 +123,7 @@ test("usage.agents filters by workspace and merges the registry", async () => {
123
123
  }
124
124
  });
125
125
 
126
- test("skills-by-name never awaits agent.refresh", async () => {
126
+ test("skills-by-name refreshes an empty handle and resolves project skills", async () => {
127
127
  const dir = mkdtempSync(join(tmpdir(), "fast-skills-"));
128
128
  const store = createUsageStore({ dir, driver: "sqlite" });
129
129
  let refreshed = 0;
@@ -133,15 +133,36 @@ test("skills-by-name never awaits agent.refresh", async () => {
133
133
  current: () => null,
134
134
  refresh: async () => {
135
135
  refreshed += 1;
136
+ return { agent: { id: "a1", provider: "codex", cwd: dir } };
136
137
  },
137
138
  }),
138
139
  },
139
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;
140
162
  try {
141
163
  store.upsertMany([row()]);
142
164
  const result = await createSkillsByNameHandler(store)({ agentId: "a1" }, { paseo });
143
165
  assert.equal(result.items[0]?.skillName, "demo");
144
- assert.equal(refreshed, 0);
145
166
  } finally {
146
167
  store.close();
147
168
  rmSync(dir, { recursive: true, force: true });
@@ -151,14 +151,21 @@ export function createListHandler(store: UsageStore) {
151
151
  };
152
152
  }
153
153
 
154
- function skillRootsForQuery(
154
+ async function skillRootsForQuery(
155
155
  paseo: PaseoApi,
156
156
  agentId: string | undefined,
157
157
  homeDir: string,
158
- ): string[] {
158
+ ): Promise<string[]> {
159
159
  if (!agentId) return buildHomeSkillRoots(homeDir);
160
160
  const handle = paseo.agents.ref(agentId);
161
- 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
+ }
162
169
  if (snapshot?.cwd) {
163
170
  return buildSkillRoots(agentFromSnapshot(snapshot), homeDir);
164
171
  }
@@ -178,7 +185,7 @@ export function createSkillsByNameHandler(store: UsageStore) {
178
185
  from: input.from,
179
186
  to: input.to,
180
187
  });
181
- const roots = skillRootsForQuery(context.paseo, input.agentId, homeDir);
188
+ const roots = await skillRootsForQuery(context.paseo, input.agentId, homeDir);
182
189
  const items = finalizeSkillPaths(aggregateSkillsByName(rows), roots, homeDir);
183
190
  return { items };
184
191
  };
@@ -248,7 +255,12 @@ export function createAgentsHandler(store: UsageStore) {
248
255
  };
249
256
  }
250
257
 
251
- /** Host Unarchive ≡ refreshAgent; CLI surface is `paseo agent reload`. */
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
+ */
252
264
  export function createUnarchiveAgentHandler(store: UsageStore) {
253
265
  return async (
254
266
  input: RpcInput<typeof usageAgentUnarchiveRpc>,
@@ -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[] {
@@ -1,52 +1,56 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import { formatDayTime, formatDisplayName, formatUpdatedAt } from "./format.ts";
3
+ import {
4
+ formatActivityTime,
5
+ formatDisplayName,
6
+ formatLocalDateTime,
7
+ formatUpdatedAt,
8
+ } from "./format.ts";
4
9
 
5
10
  const NOW = new Date(2026, 8, 18, 15, 30);
6
11
 
7
- describe("formatDayTime", () => {
8
- it("shows only HH:mm for the same local day", () => {
9
- assert.equal(formatDayTime(new Date(2026, 8, 18, 9, 5).toISOString(), NOW), "09:05");
10
- assert.equal(formatDayTime(new Date(2026, 8, 18, 23, 59).toISOString(), NOW), "23:59");
12
+ describe("formatActivityTime", () => {
13
+ it("shows only the time for the same local day", () => {
14
+ const text = formatActivityTime(new Date(2026, 8, 18, 9, 5).toISOString(), "en", NOW);
15
+ assert.match(text, /09:05|9:05/);
16
+ assert.doesNotMatch(text, /Sep/);
17
+ assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
11
18
  });
12
19
 
13
- it("adds MM-DD for another day in the same year", () => {
14
- assert.equal(formatDayTime(new Date(2026, 8, 17, 14, 2).toISOString(), NOW), "09-17 14:02");
15
- assert.equal(formatDayTime(new Date(2026, 0, 3, 0, 7).toISOString(), NOW), "01-03 00:07");
16
- });
17
-
18
- it("adds the year for a different year", () => {
19
- assert.equal(
20
- formatDayTime(new Date(2025, 11, 31, 23, 59).toISOString(), NOW),
21
- "2025-12-31 23:59",
22
- );
23
- });
24
-
25
- it("returns the placeholder for empty and keeps invalid input", () => {
26
- assert.equal(formatDayTime(null, NOW), "—");
27
- assert.equal(formatDayTime(undefined, NOW), "—");
28
- assert.equal(formatDayTime("not-a-date", NOW), "not-a-date");
29
- });
30
- });
31
-
32
- describe("formatUpdatedAt", () => {
33
- it("uses locale month/day + time for the same year", () => {
34
- const text = formatUpdatedAt(new Date(2026, 8, 17, 14, 2).toISOString(), "en", NOW);
20
+ it("adds month/day for another day in the same year", () => {
21
+ const text = formatActivityTime(new Date(2026, 8, 17, 14, 2).toISOString(), "en", NOW);
35
22
  assert.match(text, /Sep/);
36
23
  assert.match(text, /17/);
24
+ assert.match(text, /14:02/);
37
25
  assert.doesNotMatch(text, /2026/);
26
+ assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
38
27
  });
39
28
 
40
29
  it("includes the year when the date is not this year", () => {
41
- const text = formatUpdatedAt(new Date(2025, 11, 31, 23, 59).toISOString(), "en", NOW);
30
+ const text = formatActivityTime(new Date(2025, 11, 31, 23, 59).toISOString(), "en", NOW);
42
31
  assert.match(text, /2025/);
43
32
  assert.match(text, /Dec/);
33
+ assert.match(text, /23:59/);
34
+ assert.doesNotMatch(text, /\bAM\b|\bPM\b/i);
44
35
  });
45
36
 
46
37
  it("returns the placeholder for empty and keeps invalid input", () => {
47
- assert.equal(formatUpdatedAt(null, "en", NOW), "—");
48
- assert.equal(formatUpdatedAt(undefined, "en", NOW), "—");
49
- assert.equal(formatUpdatedAt("not-a-date", "en", NOW), "not-a-date");
38
+ assert.equal(formatActivityTime(null, "en", NOW), "—");
39
+ assert.equal(formatActivityTime(undefined, "en", NOW), "—");
40
+ assert.equal(formatActivityTime("not-a-date", "en", NOW), "not-a-date");
41
+ });
42
+
43
+ it("keeps formatUpdatedAt as an alias", () => {
44
+ assert.equal(formatUpdatedAt, formatActivityTime);
45
+ });
46
+ });
47
+
48
+ describe("formatLocalDateTime", () => {
49
+ it("defaults to English locale style", () => {
50
+ const text = formatLocalDateTime(new Date(2026, 8, 17, 14, 2).toISOString());
51
+ assert.match(text, /Sep/);
52
+ assert.match(text, /17/);
53
+ assert.match(text, /2026/);
50
54
  });
51
55
  });
52
56