@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
@@ -16,8 +16,29 @@ export type AgentStatusInfo = {
16
16
  rank: number;
17
17
  updatedAt: string | null;
18
18
  status: string | null;
19
+ permissionCount: number;
20
+ requiresAttention: boolean;
21
+ attentionReason: string | null;
19
22
  };
20
23
 
24
+ /** Icon highlight for attention states; permission keeps the 033 warning badge. */
25
+ export type AgentAttentionKind = "finished" | "permission" | "error" | null;
26
+
27
+ export function attentionKind(info: AgentStatusInfo | undefined): AgentAttentionKind {
28
+ if (!info) return null;
29
+ if (info.status === "error") return "error";
30
+ if (info.permissionCount > 0) return "permission";
31
+ if (!info.requiresAttention) return null;
32
+ if (info.attentionReason === "error") return "error";
33
+ if (info.attentionReason === "finished") return "finished";
34
+ return null;
35
+ }
36
+
37
+ /** Host lifecycle says the agent is actively working a turn (spinner badge). */
38
+ export function isAgentRunning(info: AgentStatusInfo | undefined): boolean {
39
+ return info?.status === "running";
40
+ }
41
+
21
42
  export type MenuOption = { id: string; label: string; icon: string };
22
43
 
23
44
  /** Agents header row / search pill height — keep fixed to avoid layout jump. */
@@ -29,10 +50,13 @@ export const MENU_SUBMENU_OVERLAP = 5;
29
50
  export const MENU_WIDTH = 232;
30
51
  export const MENU_OPTION_ICON_SIZE = 14;
31
52
  /** Approx list-row height (padding + title/meta) for stable Skills/MCP section size. */
32
- export const RANK_ROW_ESTIMATE = 54;
53
+ export const RANK_ROW_ESTIMATE = 42;
33
54
  /** Visible agents per page in Explorer; pager hidden when pageCount ≤ 1. */
34
55
  export const AGENT_PAGE_SIZE = 40;
35
56
  export const HOST_AGENT_PAGE_LIMIT = 200;
57
+ /** Open terminals poll cadence; the capture preview polls at the same rate while expanded. */
58
+ export const TERMINAL_REFETCH_MS = 5_000;
59
+ export const TERMINAL_PREVIEW_LINES = 8;
36
60
 
37
61
  export const SORT_OPTIONS: ReadonlyArray<MenuOption & { id: AgentSort }> = [
38
62
  { id: "updated", label: "Updated", icon: "Clock" },
@@ -81,12 +105,14 @@ export function attentionRank(agent: {
81
105
  status?: string;
82
106
  requiresAttention?: boolean;
83
107
  attentionReason?: string | null;
108
+ pendingPermissions?: ReadonlyArray<unknown>;
84
109
  }): number {
85
110
  if (
86
111
  agent.requiresAttention === true ||
87
112
  agent.attentionReason === "permission" ||
88
113
  agent.attentionReason === "error" ||
89
- agent.status === "error"
114
+ agent.status === "error" ||
115
+ (agent.pendingPermissions?.length ?? 0) > 0
90
116
  ) {
91
117
  return 0;
92
118
  }
@@ -117,5 +143,5 @@ export function agentUpdatedAt(
117
143
  item: AgentUsageItem,
118
144
  byId: Record<string, AgentStatusInfo> | undefined,
119
145
  ): string | null {
120
- return item.updatedAt ?? byId?.[item.agentId]?.updatedAt ?? item.lastActivityAt ?? null;
146
+ return byId?.[item.agentId]?.updatedAt ?? item.updatedAt ?? item.lastActivityAt ?? null;
121
147
  }
@@ -1,5 +1,5 @@
1
1
  import { matchesAgentTitleSearch } from "../../shared/agent-title-search.ts";
2
- import { formatUpdatedAt } from "../../shared/format.ts";
2
+ import { formatActivityTime } from "../../shared/format.ts";
3
3
  import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
4
4
  import {
5
5
  type AgentShowField,
@@ -23,7 +23,7 @@ export function formatAgentMeta(
23
23
  if (showFields.has("messages")) parts.push(`${item.messageCount} messages`);
24
24
  if (showFields.has("updated")) {
25
25
  const at = agentUpdatedAt(item, byId);
26
- if (at) parts.push(formatUpdatedAt(at, locale));
26
+ if (at) parts.push(formatActivityTime(at, locale));
27
27
  }
28
28
  if (parts.length === 0) return null;
29
29
  return parts.join(" · ");
@@ -0,0 +1,45 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { attentionKind } from "./constants.ts";
4
+ import { loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
5
+
6
+ test("workspace status uses daemon placement project ID on every page and rejects other workspaces", async () => {
7
+ let pages = 0;
8
+ const map = await loadWorkspaceAgentStatuses({ agents: { list: async (options) => {
9
+ assert.deepEqual(options.filter, { includeArchived: true, projectKeys: ["prj_c187d0857b6da810"] });
10
+ pages++;
11
+ return {
12
+ entries: [{ agent: { id: `a${pages}`, workspaceId: pages === 1 ? "other" : "w", pendingPermissions: [{}] } },
13
+ { agent: { id: "unknown" } }],
14
+ pageInfo: { hasMore: pages === 1, nextCursor: pages === 1 ? "next" : null },
15
+ };
16
+ } } }, "w", "prj_c187d0857b6da810");
17
+ assert.equal(pages, 2);
18
+ assert.deepEqual(Object.keys(map), ["a2"]);
19
+ assert.equal(map.a2?.permissionCount, 1);
20
+ });
21
+
22
+ // Reproduce daemon 0.8's structural filter, including the two different keys.
23
+ test("pending questions survive a poll when catalog key differs from placement key", async () => {
24
+ const workspace = { id: "w", projectId: "prj_project" };
25
+ const project = { projectId: workspace.projectId, projectKey: "remote:github.com/org/repo" };
26
+ const entry = {
27
+ agent: { id: "waiting", workspaceId: workspace.id, status: "running",
28
+ requiresAttention: false, attentionReason: null, pendingPermissions: [{ tool: "question" }] },
29
+ project: { projectKey: project.projectId },
30
+ };
31
+ const paseo = { agents: { list: async (options: { filter?: { projectKeys?: string[] } }) => ({
32
+ entries: !options.filter?.projectKeys || options.filter.projectKeys.includes(entry.project.projectKey) ? [entry] : [],
33
+ pageInfo: { hasMore: false, nextCursor: null },
34
+ }) } };
35
+ const incorrect = await loadWorkspaceAgentStatuses(paseo, workspace.id, project.projectKey);
36
+ assert.deepEqual(incorrect, {});
37
+ for (let poll = 0; poll < 2; poll++) {
38
+ const statuses = await loadWorkspaceAgentStatuses(paseo, workspace.id, workspace.projectId);
39
+ assert.equal(statuses.waiting?.permissionCount, 1);
40
+ assert.equal(statuses.waiting?.rank, 0);
41
+ assert.equal(attentionKind(statuses.waiting), "permission");
42
+ }
43
+ const fallback = await loadWorkspaceAgentStatuses(paseo, workspace.id);
44
+ assert.equal(fallback.waiting?.permissionCount, 1);
45
+ });
@@ -5,7 +5,7 @@ import {
5
5
  type AgentStatusInfo,
6
6
  } from "./constants.ts";
7
7
 
8
- type HostAgentEntry = {
8
+ export type HostAgentEntry = {
9
9
  agent: {
10
10
  id: string;
11
11
  workspaceId?: string;
@@ -13,13 +13,19 @@ type HostAgentEntry = {
13
13
  updatedAt?: string;
14
14
  requiresAttention?: boolean;
15
15
  attentionReason?: string | null;
16
+ pendingPermissions?: ReadonlyArray<unknown>;
16
17
  };
17
18
  };
18
19
 
20
+ export type HostAgentUpdate =
21
+ | { kind: "remove"; agentId: string }
22
+ | { kind: "upsert"; agent: HostAgentEntry["agent"] };
23
+
19
24
  type HostAgentsApi = {
20
25
  agents: {
26
+ subscribe?: (handler: (update: HostAgentUpdate) => void) => () => void;
21
27
  list: (options: {
22
- filter?: { includeArchived?: boolean };
28
+ filter?: { includeArchived?: boolean; projectKeys?: string[] };
23
29
  page?: { limit: number; cursor?: string };
24
30
  }) => Promise<{
25
31
  entries: ReadonlyArray<HostAgentEntry>;
@@ -28,30 +34,57 @@ type HostAgentsApi = {
28
34
  };
29
35
  };
30
36
 
31
- /** Fetch all host agents (paged) and build workspace-scoped status enrichment. */
37
+ /**
38
+ * Fetch project agents then enforce workspace scope. In daemon 0.8,
39
+ * ProjectPlacement.projectKey is projectId; the project catalog's repository
40
+ * key is a different identifier and produces an empty agent directory.
41
+ */
32
42
  export async function loadWorkspaceAgentStatuses(
33
43
  paseo: HostAgentsApi,
34
44
  workspaceId: string,
45
+ projectId?: string | null,
35
46
  ): Promise<Record<string, AgentStatusInfo>> {
36
- const entries = await listAllAgentPages(
37
- async (cursor) => {
38
- const result = await paseo.agents.list({
39
- filter: { includeArchived: true },
40
- page: { limit: HOST_AGENT_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
41
- });
42
- return { entries: result.entries, pageInfo: result.pageInfo };
43
- },
44
- );
47
+ const pending: HostAgentUpdate[] = [];
48
+ const unsubscribe = paseo.agents.subscribe?.((update) => pending.push(update));
49
+ try {
50
+ const entries = await listAllAgentPages(
51
+ async (cursor) => {
52
+ const result = await paseo.agents.list({
53
+ filter: { includeArchived: true, ...(projectId ? { projectKeys: [projectId] } : {}) },
54
+ page: { limit: HOST_AGENT_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
55
+ });
56
+ return { entries: result.entries, pageInfo: result.pageInfo };
57
+ },
58
+ );
45
59
 
46
- const map: Record<string, AgentStatusInfo> = {};
47
- for (const entry of entries) {
48
- const agent = entry.agent;
49
- if (agent.workspaceId && agent.workspaceId !== workspaceId) continue;
50
- map[agent.id] = {
51
- rank: attentionRank(agent),
52
- updatedAt: agent.updatedAt ?? null,
53
- status: agent.status ?? null,
54
- };
60
+ const map: Record<string, AgentStatusInfo> = {};
61
+ for (const entry of entries) {
62
+ const agent = entry.agent;
63
+ if (agent.workspaceId !== workspaceId) continue;
64
+ map[agent.id] = agentStatusInfo(agent);
65
+ }
66
+ for (const update of pending) applyAgentStatusUpdate(map, workspaceId, update);
67
+ return map;
68
+ } finally {
69
+ unsubscribe?.();
55
70
  }
56
- return map;
71
+ }
72
+
73
+ export function applyAgentStatusUpdate(
74
+ map: Record<string, AgentStatusInfo>, workspaceId: string, update: HostAgentUpdate,
75
+ ): void {
76
+ const id = update.kind === "remove" ? update.agentId : update.agent.id;
77
+ if (update.kind === "remove" || update.agent.workspaceId !== workspaceId) delete map[id];
78
+ else map[id] = agentStatusInfo(update.agent);
79
+ }
80
+
81
+ export function agentStatusInfo(agent: HostAgentEntry["agent"]): AgentStatusInfo {
82
+ return {
83
+ rank: attentionRank(agent),
84
+ updatedAt: agent.updatedAt ?? null,
85
+ status: agent.status ?? null,
86
+ permissionCount: agent.pendingPermissions?.length ?? 0,
87
+ requiresAttention: agent.requiresAttention === true,
88
+ attentionReason: agent.attentionReason ?? null,
89
+ };
57
90
  }
@@ -1,12 +1,14 @@
1
+ import { updateWorkspaceStatusCache } from "./status-cache.ts";
1
2
  import {
2
3
  type PluginWorkspacePanelProps,
3
4
  usePaseo,
4
5
  useRpc,
5
6
  useSettings,
7
+ useWorkspace,
6
8
  } from "@getpaseo/plugin/client";
7
9
  import { useToast } from "@getpaseo/plugin/client/react-native";
8
10
  import { useQuery, useQueryClient } from "@tanstack/react-query";
9
- import { useMemo, useRef, useState } from "react";
11
+ import { useEffect, useMemo, useRef, useState } from "react";
10
12
  import {
11
13
  ActivityIndicator,
12
14
  Dimensions,
@@ -26,11 +28,13 @@ import {
26
28
  type AgentUsageItem,
27
29
  usageAgentUnarchiveRpc,
28
30
  usageAgentsRpc,
31
+ usageHostInfoRpc,
29
32
  usageMcpByToolRpc,
30
33
  usageSkillsByNameRpc,
31
34
  usageSummaryRpc,
32
35
  } from "../../shared/usage.ts";
33
36
  import { useAppLanguage } from "../use-app-language.ts";
37
+ import { useWorkspaceActivityRefresh } from "../use-agent-turn-end.ts";
34
38
  import { UsageStats } from "../usage-stats.tsx";
35
39
  import { AgentsSection } from "./agents-section.tsx";
36
40
  import {
@@ -42,6 +46,7 @@ import {
42
46
  SHOW_FIELD_OPTIONS,
43
47
  SORT_OPTIONS,
44
48
  STATUS_FILTER_OPTIONS,
49
+ TERMINAL_REFETCH_MS,
45
50
  agentUpdatedAt,
46
51
  matchesAgentFilters,
47
52
  optionLabel,
@@ -57,9 +62,12 @@ import { MenuOptionList, MenuSubTrigger } from "./display-menu.tsx";
57
62
  import { matchesAgentTitle } from "./filters.ts";
58
63
  import { loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
59
64
  import { RankSection } from "./rank-section.tsx";
65
+ import { TerminalsSection, type TerminalListItem } from "./terminals-section.tsx";
60
66
 
61
67
  type RankKind = "skills" | "mcp";
62
68
 
69
+ const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
70
+
63
71
  /** Workspace-scoped Activity for the Explorer (024 / 031). */
64
72
  export function WorkspaceActivityPanel({
65
73
  theme,
@@ -92,6 +100,7 @@ export function WorkspaceActivityPanel({
92
100
  const [agentSearchQuery, setAgentSearchQuery] = useState("");
93
101
  const [rankKind, setRankKind] = useState<RankKind>("skills");
94
102
  const [busyAgentId, setBusyAgentId] = useState<string | null>(null);
103
+ const [busyTerminalId, setBusyTerminalId] = useState<string | null>(null);
95
104
  const padding = layout.compact ? 16 : 24;
96
105
  const locale = useAppLanguage();
97
106
  const toast = useToast();
@@ -110,8 +119,10 @@ export function WorkspaceActivityPanel({
110
119
  const unarchiveAgentRpc = useRpc(usageAgentUnarchiveRpc);
111
120
  const skillsRpc = useRpc(usageSkillsByNameRpc);
112
121
  const mcpRpc = useRpc(usageMcpByToolRpc);
122
+ const hostInfoRpc = useRpc(usageHostInfoRpc);
113
123
 
114
124
  const agentsQueryKey = ["activity", "workspace-agents", workspaceId] as const;
125
+ const terminalsQueryKey = ["activity", "workspace-terminals", workspaceId] as const;
115
126
 
116
127
  const summary = useQuery({
117
128
  refetchInterval: 15_000,
@@ -142,11 +153,51 @@ export function WorkspaceActivityPanel({
142
153
  });
143
154
 
144
155
  const paseo = usePaseo();
156
+ const terminals = useQuery({
157
+ refetchInterval: TERMINAL_REFETCH_MS,
158
+ retry: false,
159
+ queryKey: terminalsQueryKey,
160
+ queryFn: () => paseo.terminals.list({ workspaceId }),
161
+ });
162
+
163
+ const hostInfo = useQuery({
164
+ staleTime: Infinity,
165
+ retry: false,
166
+ queryKey: ["activity", "host-info"],
167
+ queryFn: () => hostInfoRpc({}),
168
+ });
169
+
170
+ const projectId = useWorkspace(workspaceId, (workspace) => workspace.projectId);
171
+ // 0.8 agent directory filters match ProjectPlacement.projectKey, which the
172
+ // daemon builds from projectId, NOT WorkspaceProjectDescriptor.projectKey.
173
+ const statusQueryKey = useMemo(
174
+ () => ["activity", "workspace-agent-status", workspaceId, projectId ?? null],
175
+ [workspaceId, projectId],
176
+ );
145
177
  const statuses = useQuery({
146
178
  refetchInterval: 15_000,
147
179
  retry: false,
148
- queryKey: ["activity", "workspace-agent-status", workspaceId],
149
- queryFn: () => loadWorkspaceAgentStatuses(paseo, workspaceId),
180
+ queryKey: statusQueryKey,
181
+ queryFn: () => loadWorkspaceAgentStatuses(paseo, workspaceId, projectId),
182
+ });
183
+
184
+ useEffect(() => paseo.agents.subscribe((update) => {
185
+ // This local listener accelerates the owned polling query without taking the
186
+ // daemon's shared observation slot or re-fetching the directory on each push.
187
+ updateWorkspaceStatusCache(queryClient, statusQueryKey, workspaceId, update);
188
+ }), [paseo, queryClient, workspaceId, statusQueryKey]);
189
+
190
+ useWorkspaceActivityRefresh(workspaceId, () => {
191
+ void queryClient.invalidateQueries({
192
+ queryKey: ["activity", "workspace-summary", workspaceId],
193
+ });
194
+ void queryClient.invalidateQueries({ queryKey: agentsQueryKey });
195
+ void queryClient.invalidateQueries({
196
+ queryKey: ["activity", "workspace-skills", workspaceId],
197
+ });
198
+ void queryClient.invalidateQueries({
199
+ queryKey: ["activity", "workspace-mcp", workspaceId],
200
+ });
150
201
  });
151
202
 
152
203
  const agentItems = agents.data?.items ?? [];
@@ -195,7 +246,10 @@ export function WorkspaceActivityPanel({
195
246
  () => (skills.data?.items ?? []).filter((item) => item.total > 0),
196
247
  [skills.data],
197
248
  );
198
- const allMcp = mcp.data?.items ?? [];
249
+ const allMcp = useMemo(
250
+ () => (mcp.data?.items ?? []).filter((item) => item.count > 0),
251
+ [mcp.data],
252
+ );
199
253
  const skillItems = useMemo(() => allSkills.slice(0, ACTIVITY_LIST_LIMIT), [allSkills]);
200
254
  const mcpItems = useMemo(() => allMcp.slice(0, ACTIVITY_LIST_LIMIT), [allMcp]);
201
255
 
@@ -213,9 +267,18 @@ export function WorkspaceActivityPanel({
213
267
  },
214
268
  ];
215
269
 
270
+ const terminalItems = terminals.data?.entries ?? [];
216
271
  const showAgents = agentItems.length > 0;
217
272
  const showRank = skillItems.length > 0 || mcpItems.length > 0;
218
- const showContent = showAgents || showRank;
273
+ const showRankToggle = skillItems.length > 0 && mcpItems.length > 0;
274
+ const showTerminals = terminalItems.length > 0;
275
+ const showContent = showAgents || showRank || showTerminals;
276
+
277
+ useEffect(() => {
278
+ if (skillItems.length === 0 && mcpItems.length === 0) return;
279
+ if (rankKind === "skills" && skillItems.length === 0) setRankKind("mcp");
280
+ else if (rankKind === "mcp" && mcpItems.length === 0) setRankKind("skills");
281
+ }, [skillItems.length, mcpItems.length, rankKind]);
219
282
 
220
283
  const styles = useMemo(
221
284
  () => ({
@@ -304,21 +367,21 @@ export function WorkspaceActivityPanel({
304
367
  },
305
368
  sectionTitle: {
306
369
  color: theme.colors.foreground,
307
- fontSize: layout.compact ? 18 : 20,
370
+ fontSize: 16,
308
371
  fontWeight: "600" as const,
309
372
  flexShrink: 0,
310
373
  letterSpacing: -0.3,
311
374
  lineHeight: AGENT_HEADER_HEIGHT,
312
375
  },
313
376
  panel: {
314
- gap: 4,
377
+ gap: 2,
315
378
  overflow: "hidden" as const,
316
379
  },
317
380
  listRow: {
318
381
  flexDirection: "row" as const,
319
382
  alignItems: "center" as const,
320
383
  gap: 12,
321
- paddingVertical: 12,
384
+ paddingVertical: 6,
322
385
  },
323
386
  agentListRow: {
324
387
  flexDirection: "row" as const,
@@ -326,6 +389,23 @@ export function WorkspaceActivityPanel({
326
389
  gap: 10,
327
390
  paddingVertical: 6,
328
391
  },
392
+ agentIconWrap: {
393
+ width: 18,
394
+ height: 18,
395
+ alignItems: "center" as const,
396
+ justifyContent: "center" as const,
397
+ },
398
+ runningBadge: {
399
+ position: "absolute" as const,
400
+ right: -4,
401
+ bottom: -4,
402
+ width: 13,
403
+ height: 13,
404
+ borderRadius: 6.5,
405
+ alignItems: "center" as const,
406
+ justifyContent: "center" as const,
407
+ backgroundColor: theme.colors.surface0,
408
+ },
329
409
  listMain: {
330
410
  flex: 1,
331
411
  minWidth: 0,
@@ -345,6 +425,45 @@ export function WorkspaceActivityPanel({
345
425
  color: theme.colors.foregroundMuted,
346
426
  fontSize: 12,
347
427
  },
428
+ permissionBadge: {
429
+ flexDirection: "row" as const,
430
+ alignItems: "center" as const,
431
+ gap: 3,
432
+ height: 18,
433
+ paddingHorizontal: 5,
434
+ borderRadius: 9,
435
+ borderWidth: 1,
436
+ borderColor: theme.colors.border,
437
+ backgroundColor: theme.colors.surface1,
438
+ flexShrink: 0,
439
+ },
440
+ permissionBadgeText: {
441
+ color: theme.colors.statusWarning,
442
+ fontSize: 11,
443
+ fontWeight: "600" as const,
444
+ fontVariant: ["tabular-nums" as const],
445
+ },
446
+ terminalRow: {
447
+ flexDirection: "row" as const,
448
+ alignItems: "center" as const,
449
+ gap: 10,
450
+ paddingVertical: 6,
451
+ },
452
+ terminalPreview: {
453
+ marginLeft: 28,
454
+ marginBottom: 4,
455
+ paddingVertical: 8,
456
+ paddingHorizontal: 10,
457
+ borderRadius: 6,
458
+ backgroundColor: theme.colors.surface1,
459
+ gap: 2,
460
+ },
461
+ terminalLine: {
462
+ color: theme.colors.foregroundMuted,
463
+ fontFamily: MONO,
464
+ fontSize: 11,
465
+ lineHeight: 15,
466
+ },
348
467
  countText: {
349
468
  color: theme.colors.foregroundMuted,
350
469
  fontSize: 13,
@@ -653,6 +772,38 @@ export function WorkspaceActivityPanel({
653
772
  }
654
773
  }
655
774
 
775
+ function patchTerminalRemoved(terminalId: string) {
776
+ queryClient.setQueryData<{ entries: TerminalListItem[]; requestId: string }>(
777
+ terminalsQueryKey,
778
+ (prev) =>
779
+ prev
780
+ ? { ...prev, entries: prev.entries.filter((entry) => entry.id !== terminalId) }
781
+ : prev,
782
+ );
783
+ }
784
+
785
+ async function closeTerminal(item: TerminalListItem) {
786
+ if (busyTerminalId != null) return;
787
+ setBusyTerminalId(item.id);
788
+ const previous = queryClient.getQueryData<{
789
+ entries: TerminalListItem[];
790
+ requestId: string;
791
+ }>(terminalsQueryKey);
792
+ patchTerminalRemoved(item.id);
793
+ try {
794
+ await paseo.terminals.ref(item.id).kill();
795
+ queryClient.removeQueries({
796
+ queryKey: ["activity", "terminal-capture", workspaceId, item.id],
797
+ });
798
+ await queryClient.invalidateQueries({ queryKey: terminalsQueryKey });
799
+ } catch (err) {
800
+ if (previous) queryClient.setQueryData(terminalsQueryKey, previous);
801
+ toast.error(err instanceof Error ? err.message : String(err));
802
+ } finally {
803
+ setBusyTerminalId(null);
804
+ }
805
+ }
806
+
656
807
  return (
657
808
  <View ref={rootRef} collapsable={false} style={styles.shell}>
658
809
  <View style={styles.screen}>
@@ -706,12 +857,25 @@ export function WorkspaceActivityPanel({
706
857
  />
707
858
  ) : null}
708
859
 
860
+ {showTerminals ? (
861
+ <TerminalsSection
862
+ workspaceId={workspaceId}
863
+ terminalItems={terminalItems}
864
+ busyTerminalId={busyTerminalId}
865
+ homeDir={hostInfo.data?.homeDir}
866
+ mutedColor={theme.colors.foregroundMuted}
867
+ styles={styles}
868
+ onClose={(item) => void closeTerminal(item)}
869
+ />
870
+ ) : null}
871
+
709
872
  {showRank ? (
710
873
  <RankSection
711
874
  rankKind={rankKind}
712
875
  onToggleKind={() =>
713
876
  setRankKind((prev) => (prev === "skills" ? "mcp" : "skills"))
714
877
  }
878
+ showToggle={showRankToggle}
715
879
  skillItems={skillItems}
716
880
  mcpItems={mcpItems}
717
881
  mutedColor={theme.colors.foregroundMuted}
@@ -1,8 +1,9 @@
1
1
  import { Icon } from "@getpaseo/plugin/client/react-native";
2
2
  import type { ReactNode } from "react";
3
3
  import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
- import { formatDisplayName, formatLocalDateTime } from "../../shared/format.ts";
4
+ import { formatDisplayName } from "../../shared/format.ts";
5
5
  import type { McpByToolItem, SkillByNameItem } from "../../shared/usage.ts";
6
+ import { FormattedTime } from "../formatted-time.tsx";
6
7
  import { RANK_ROW_ESTIMATE } from "./constants.ts";
7
8
 
8
9
  type RankKind = "skills" | "mcp";
@@ -43,6 +44,7 @@ export type RankSectionStyles = {
43
44
  export function RankSection({
44
45
  rankKind,
45
46
  onToggleKind,
47
+ showToggle = true,
46
48
  skillItems,
47
49
  mcpItems,
48
50
  mutedColor,
@@ -50,30 +52,37 @@ export function RankSection({
50
52
  }: {
51
53
  rankKind: RankKind;
52
54
  onToggleKind: () => void;
55
+ showToggle?: boolean;
53
56
  skillItems: ReadonlyArray<SkillByNameItem>;
54
57
  mcpItems: ReadonlyArray<McpByToolItem>;
55
58
  mutedColor: string;
56
59
  styles: RankSectionStyles;
57
60
  }): ReactNode {
61
+ if (skillItems.length === 0 && mcpItems.length === 0) return null;
62
+
63
+ const items = rankKind === "skills" ? skillItems : mcpItems;
64
+
58
65
  return (
59
66
  <View style={{ gap: 12 }}>
60
67
  <View style={styles.sectionHeaderRow}>
61
68
  <Text style={styles.sectionTitle}>{rankTitle(rankKind)}</Text>
62
- <Pressable
63
- accessibilityRole="button"
64
- accessibilityLabel={rankAction(rankKind).accessibilityLabel}
65
- hitSlop={8}
66
- onPress={onToggleKind}
67
- style={styles.titleAction}
68
- >
69
- <Icon name={rankAction(rankKind).icon} size={16} color={mutedColor} />
70
- </Pressable>
69
+ {showToggle ? (
70
+ <Pressable
71
+ accessibilityRole="button"
72
+ accessibilityLabel={rankAction(rankKind).accessibilityLabel}
73
+ hitSlop={8}
74
+ onPress={onToggleKind}
75
+ style={styles.titleAction}
76
+ >
77
+ <Icon name={rankAction(rankKind).icon} size={16} color={mutedColor} />
78
+ </Pressable>
79
+ ) : null}
71
80
  </View>
72
81
  <View
73
82
  style={[
74
83
  styles.panel,
75
84
  {
76
- minHeight: Math.max(skillItems.length, mcpItems.length, 1) * RANK_ROW_ESTIMATE,
85
+ minHeight: Math.max(items.length, 1) * RANK_ROW_ESTIMATE,
77
86
  },
78
87
  ]}
79
88
  >
@@ -85,9 +94,11 @@ export function RankSection({
85
94
  <Text style={styles.listTitle} numberOfLines={1}>
86
95
  {formatDisplayName(item.skillName)}
87
96
  </Text>
88
- <Text style={styles.listMeta}>
89
- Last {formatLocalDateTime(item.lastUsedAt)}
90
- </Text>
97
+ <FormattedTime
98
+ iso={item.lastUsedAt}
99
+ prefix="Last "
100
+ style={styles.listMeta}
101
+ />
91
102
  </View>
92
103
  <CountText value={item.total} styles={styles} />
93
104
  </View>
@@ -99,22 +110,21 @@ export function RankSection({
99
110
  <Text style={styles.listTitle} numberOfLines={1}>
100
111
  {formatDisplayName(`${item.server}.${item.tool}`)}
101
112
  </Text>
102
- <Text style={styles.listMeta}>
103
- {item.failures > 0
104
- ? `${item.failures} failed`
105
- : item.lastUsedAt
106
- ? `Last ${formatLocalDateTime(item.lastUsedAt)}`
107
- : "—"}
108
- </Text>
113
+ {item.failures > 0 ? (
114
+ <Text style={styles.listMeta}>{item.failures} failed</Text>
115
+ ) : item.lastUsedAt ? (
116
+ <FormattedTime
117
+ iso={item.lastUsedAt}
118
+ prefix="Last "
119
+ style={styles.listMeta}
120
+ />
121
+ ) : (
122
+ <Text style={styles.listMeta}>—</Text>
123
+ )}
109
124
  </View>
110
125
  <CountText value={item.count} styles={styles} />
111
126
  </View>
112
127
  ))}
113
- {(rankKind === "skills" ? skillItems.length : mcpItems.length) === 0 ? (
114
- <Text style={styles.empty}>
115
- {rankKind === "skills" ? "No skills yet" : "No MCP yet"}
116
- </Text>
117
- ) : null}
118
128
  </View>
119
129
  </View>
120
130
  );