@koinzhang/paseo-plugin-activity 0.3.0 → 0.4.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.
@@ -10,15 +10,18 @@ import {
10
10
  type ViewStyle,
11
11
  } from "react-native";
12
12
  import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
13
+ import { useLatestUserMessagePreview } from "../use-latest-user-message.ts";
13
14
  import { AgentRow, type AgentRowStyles } from "./agent-row.tsx";
14
15
  import {
15
16
  AGENT_PAGE_SIZE,
16
17
  attentionKind,
18
+ countSubAgentsByParent,
17
19
  isAgentRunning,
18
20
  SEARCH_ANIM_MS,
19
21
  SEARCH_TITLE_GAP,
20
22
  type AgentGroup,
21
23
  type AgentShowField,
24
+ type AgentStatusFilter,
22
25
  type AgentStatusInfo,
23
26
  } from "./constants.ts";
24
27
  import { formatAgentMeta } from "./filters.ts";
@@ -44,6 +47,72 @@ export type AgentsSectionStyles = AgentRowStyles & {
44
47
  pagerLabel: TextStyle;
45
48
  };
46
49
 
50
+ function WorkspaceAgentRow({
51
+ item,
52
+ theme,
53
+ styles,
54
+ locale,
55
+ agentShowFields,
56
+ statuses,
57
+ subAgentCount,
58
+ busyAgentId,
59
+ openAgent,
60
+ onArchive,
61
+ onUnarchive,
62
+ }: {
63
+ item: AgentUsageItem;
64
+ theme: WorkspaceTheme;
65
+ styles: AgentsSectionStyles;
66
+ locale: string;
67
+ agentShowFields: ReadonlySet<AgentShowField>;
68
+ statuses: Record<string, AgentStatusInfo> | undefined;
69
+ subAgentCount: number;
70
+ busyAgentId: string | null;
71
+ openAgent?: (opts: { agentId: string }) => void;
72
+ onArchive: (item: AgentUsageItem) => void;
73
+ onUnarchive: (item: AgentUsageItem) => void;
74
+ }): ReactNode {
75
+ const showPrompt = agentShowFields.has("prompt");
76
+ const preview = useLatestUserMessagePreview(item.agentId, showPrompt);
77
+ useEffect(() => {
78
+ if (!showPrompt || !preview.isError) return;
79
+ console.warn("[activity] latest user message preview failed", item.agentId, preview.error);
80
+ }, [showPrompt, preview.isError, preview.error, item.agentId]);
81
+
82
+ const promptPreview = showPrompt
83
+ ? (preview.data ?? (preview.isLoading ? "…" : null))
84
+ : null;
85
+ const label = item.title ?? item.agentId;
86
+ const archived = item.archivedAt != null;
87
+ const canOpen = openAgent != null && !archived;
88
+ const meta = formatAgentMeta(item, agentShowFields, statuses, locale, promptPreview);
89
+ const statusInfo = statuses?.[item.agentId];
90
+ const permissionCount = statusInfo?.permissionCount ?? 0;
91
+ const busy = busyAgentId === item.agentId;
92
+
93
+ return (
94
+ <AgentRow
95
+ label={label}
96
+ archived={archived}
97
+ canOpen={canOpen}
98
+ meta={meta}
99
+ permissionCount={permissionCount}
100
+ attentionKind={attentionKind(statusInfo)}
101
+ running={isAgentRunning(statusInfo)}
102
+ subAgentCount={subAgentCount}
103
+ busy={busy}
104
+ actionDisabled={busy || busyAgentId != null}
105
+ theme={theme}
106
+ styles={styles}
107
+ onOpen={() => openAgent?.({ agentId: item.agentId })}
108
+ onArchiveToggle={() => {
109
+ if (archived) onUnarchive(item);
110
+ else onArchive(item);
111
+ }}
112
+ />
113
+ );
114
+ }
115
+
47
116
  export function AgentsSection({
48
117
  theme,
49
118
  styles,
@@ -51,7 +120,9 @@ export function AgentsSection({
51
120
  agentGroup,
52
121
  agentShowFields,
53
122
  statuses,
123
+ agentItems,
54
124
  visibleAgentItems,
125
+ statusFilters,
55
126
  statusFiltersEmpty,
56
127
  busyAgentId,
57
128
  openAgent,
@@ -70,8 +141,12 @@ export function AgentsSection({
70
141
  agentGroup: AgentGroup;
71
142
  agentShowFields: ReadonlySet<AgentShowField>;
72
143
  statuses: Record<string, AgentStatusInfo> | undefined;
144
+ /** Full workspace registry list (unfiltered) — source for subagent counts (041). */
145
+ agentItems: ReadonlyArray<AgentUsageItem>;
73
146
  /** Already filtered / sorted / search-matched. */
74
147
  visibleAgentItems: ReadonlyArray<AgentUsageItem>;
148
+ /** Status menu Active / Archived — scopes subagent badge counts. */
149
+ statusFilters: ReadonlySet<AgentStatusFilter>;
75
150
  statusFiltersEmpty: boolean;
76
151
  busyAgentId: string | null;
77
152
  openAgent?: (opts: { agentId: string }) => void;
@@ -165,33 +240,26 @@ export function AgentsSection({
165
240
  );
166
241
  }, [agentGroup, pageItems]);
167
242
 
243
+ const subAgentCounts = useMemo(
244
+ () => countSubAgentsByParent(agentItems, statusFilters),
245
+ [agentItems, statusFilters],
246
+ );
247
+
168
248
  function renderAgentRow(item: AgentUsageItem): ReactNode {
169
- const label = item.title ?? item.agentId;
170
- const archived = item.archivedAt != null;
171
- const canOpen = openAgent != null && !archived;
172
- const meta = formatAgentMeta(item, agentShowFields, statuses, locale);
173
- const statusInfo = statuses?.[item.agentId];
174
- const permissionCount = statusInfo?.permissionCount ?? 0;
175
- const busy = busyAgentId === item.agentId;
176
249
  return (
177
- <AgentRow
250
+ <WorkspaceAgentRow
178
251
  key={item.agentId}
179
- label={label}
180
- archived={archived}
181
- canOpen={canOpen}
182
- meta={meta}
183
- permissionCount={permissionCount}
184
- attentionKind={attentionKind(statusInfo)}
185
- running={isAgentRunning(statusInfo)}
186
- busy={busy}
187
- actionDisabled={busy || busyAgentId != null}
252
+ item={item}
188
253
  theme={theme}
189
254
  styles={styles}
190
- onOpen={() => openAgent?.({ agentId: item.agentId })}
191
- onArchiveToggle={() => {
192
- if (archived) onUnarchive(item);
193
- else onArchive(item);
194
- }}
255
+ locale={locale}
256
+ agentShowFields={agentShowFields}
257
+ statuses={statuses}
258
+ subAgentCount={subAgentCounts[item.agentId] ?? 0}
259
+ busyAgentId={busyAgentId}
260
+ openAgent={openAgent}
261
+ onArchive={onArchive}
262
+ onUnarchive={onUnarchive}
195
263
  />
196
264
  );
197
265
  }
@@ -0,0 +1,66 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import {
4
+ countDirectSubAgents,
5
+ countSubAgentsByParent,
6
+ type AgentStatusFilter,
7
+ type AgentStatusInfo,
8
+ } from "./constants.ts";
9
+
10
+ function info(partial: Partial<AgentStatusInfo> = {}): AgentStatusInfo {
11
+ return {
12
+ rank: 4,
13
+ updatedAt: null,
14
+ status: "idle",
15
+ permissionCount: 0,
16
+ requiresAttention: false,
17
+ attentionReason: null,
18
+ parentAgentId: null,
19
+ ...partial,
20
+ };
21
+ }
22
+
23
+ function filters(...ids: AgentStatusFilter[]): ReadonlySet<AgentStatusFilter> {
24
+ return new Set(ids);
25
+ }
26
+
27
+ const children = [
28
+ { parentAgentId: null },
29
+ { parentAgentId: "parent" },
30
+ { parentAgentId: " parent " },
31
+ { parentAgentId: "other" },
32
+ { parentAgentId: "" },
33
+ { parentAgentId: "parent", archivedAt: "2026-09-20T00:00:00.000Z" },
34
+ { parentAgentId: "gone", archivedAt: "2026-09-20T00:00:00.000Z" },
35
+ ];
36
+
37
+ test("countDirectSubAgents counts only direct children", () => {
38
+ const byId = {
39
+ parent: info(),
40
+ a: info({ parentAgentId: "parent" }),
41
+ b: info({ parentAgentId: "parent" }),
42
+ grand: info({ parentAgentId: "a" }),
43
+ other: info({ parentAgentId: "someone-else" }),
44
+ };
45
+ assert.equal(countDirectSubAgents("parent", byId), 2);
46
+ assert.equal(countDirectSubAgents("a", byId), 1);
47
+ assert.equal(countDirectSubAgents("missing", byId), 0);
48
+ assert.equal(countDirectSubAgents("parent", undefined), 0);
49
+ });
50
+
51
+ test("countSubAgentsByParent follows Status Active / Archived filters", () => {
52
+ assert.deepEqual(countSubAgentsByParent(children, filters("active")), {
53
+ parent: 2,
54
+ other: 1,
55
+ });
56
+ assert.deepEqual(countSubAgentsByParent(children, filters("archived")), {
57
+ parent: 1,
58
+ gone: 1,
59
+ });
60
+ assert.deepEqual(countSubAgentsByParent(children, filters("active", "archived")), {
61
+ parent: 3,
62
+ other: 1,
63
+ gone: 1,
64
+ });
65
+ assert.deepEqual(countSubAgentsByParent(children, filters()), {});
66
+ });
@@ -5,7 +5,7 @@ export type WorkspaceTheme = PluginWorkspacePanelProps["theme"];
5
5
 
6
6
  export type AgentSort = "created" | "updated" | "name" | "messages" | "status";
7
7
  export type AgentGroup = "none" | "provider" | "status";
8
- export type AgentShowField = "provider" | "calls" | "messages" | "updated";
8
+ export type AgentShowField = "provider" | "calls" | "messages" | "updated" | "prompt";
9
9
  /** Archive scope: Active / Archived. */
10
10
  export type AgentStatusFilter = "active" | "archived";
11
11
  /** Lifecycle for non-archived agents: Idle / Running / Error / Closed. */
@@ -19,6 +19,8 @@ export type AgentStatusInfo = {
19
19
  permissionCount: number;
20
20
  requiresAttention: boolean;
21
21
  attentionReason: string | null;
22
+ /** Host parent session; null for top-level agents. */
23
+ parentAgentId: string | null;
22
24
  };
23
25
 
24
26
  /** Icon highlight for attention states; permission keeps the 033 warning badge. */
@@ -39,6 +41,39 @@ export function isAgentRunning(info: AgentStatusInfo | undefined): boolean {
39
41
  return info?.status === "running";
40
42
  }
41
43
 
44
+ /** Direct children only (`parentAgentId === agentId`); host status map is the source. */
45
+ export function countDirectSubAgents(
46
+ agentId: string,
47
+ byId: Record<string, AgentStatusInfo> | undefined,
48
+ ): number {
49
+ if (!byId) return 0;
50
+ let count = 0;
51
+ for (const info of Object.values(byId)) {
52
+ if (info.parentAgentId === agentId) count += 1;
53
+ }
54
+ return count;
55
+ }
56
+
57
+ /** parentId → direct child count from usage.agents, scoped by Status filter (041). */
58
+ export function countSubAgentsByParent(
59
+ items: ReadonlyArray<{ parentAgentId?: string | null; archivedAt?: string | null }>,
60
+ statusFilters: ReadonlySet<AgentStatusFilter>,
61
+ ): Record<string, number> {
62
+ const includeActive = statusFilters.has("active");
63
+ const includeArchived = statusFilters.has("archived");
64
+ if (!includeActive && !includeArchived) return {};
65
+
66
+ const counts: Record<string, number> = {};
67
+ for (const item of items) {
68
+ const archived = item.archivedAt != null;
69
+ if (archived ? !includeArchived : !includeActive) continue;
70
+ const parentId = item.parentAgentId?.trim();
71
+ if (!parentId) continue;
72
+ counts[parentId] = (counts[parentId] ?? 0) + 1;
73
+ }
74
+ return counts;
75
+ }
76
+
42
77
  export type MenuOption = { id: string; label: string; icon: string };
43
78
 
44
79
  /** Agents header row / search pill height — keep fixed to avoid layout jump. */
@@ -77,6 +112,7 @@ export const SHOW_FIELD_OPTIONS: ReadonlyArray<MenuOption & { id: AgentShowField
77
112
  { id: "calls", label: "Calls", icon: "Terminal" },
78
113
  { id: "messages", label: "Messages", icon: "MessageSquare" },
79
114
  { id: "updated", label: "Updated", icon: "Clock" },
115
+ { id: "prompt", label: "Prompt", icon: "Quote" },
80
116
  ];
81
117
 
82
118
  export const STATUS_FILTER_OPTIONS: ReadonlyArray<MenuOption & { id: AgentStatusFilter }> = [
@@ -0,0 +1,59 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { formatAgentMeta } from "./filters.ts";
4
+ import type { AgentShowField, AgentStatusInfo } from "./constants.ts";
5
+ import type { AgentUsageItem } from "../../shared/usage.ts";
6
+
7
+ const item = {
8
+ agentId: "a1",
9
+ provider: "codex",
10
+ title: "Hello",
11
+ callCount: 3,
12
+ skillCalls: 0,
13
+ mcpCalls: 0,
14
+ shellCalls: 0,
15
+ fileReads: 0,
16
+ fileWrites: 0,
17
+ messageCount: 5,
18
+ coding: false,
19
+ createdAt: "2026-09-20T00:00:00.000Z",
20
+ updatedAt: "2026-09-20T01:00:00.000Z",
21
+ archivedAt: null,
22
+ parentAgentId: null,
23
+ lastActivityAt: "2026-09-20T01:00:00.000Z",
24
+ } satisfies AgentUsageItem;
25
+
26
+ function fields(...ids: AgentShowField[]): ReadonlySet<AgentShowField> {
27
+ return new Set(ids);
28
+ }
29
+
30
+ test("formatAgentMeta joins selected fields; prompt last", () => {
31
+ const byId: Record<string, AgentStatusInfo> = {
32
+ a1: {
33
+ rank: 2,
34
+ updatedAt: "2026-09-20T01:00:00.000Z",
35
+ status: "idle",
36
+ permissionCount: 0,
37
+ requiresAttention: false,
38
+ attentionReason: null,
39
+ parentAgentId: null,
40
+ },
41
+ };
42
+ assert.equal(formatAgentMeta(item, fields(), byId, "en-US"), null);
43
+ assert.equal(
44
+ formatAgentMeta(item, fields("messages", "prompt"), byId, "en-US", "ship it"),
45
+ "5 messages · ship it",
46
+ );
47
+ assert.equal(
48
+ formatAgentMeta(item, fields("prompt"), byId, "en-US", null),
49
+ null,
50
+ );
51
+ assert.equal(
52
+ formatAgentMeta(item, fields("prompt"), byId, "en-US", "…"),
53
+ "…",
54
+ );
55
+ assert.equal(
56
+ formatAgentMeta(item, fields("calls", "prompt"), byId, "en-US", ""),
57
+ "3 calls",
58
+ );
59
+ });
@@ -11,11 +11,16 @@ export function matchesAgentTitle(item: AgentUsageItem, query: string): boolean
11
11
  return matchesAgentTitleSearch(item.title ?? item.agentId, query);
12
12
  }
13
13
 
14
+ /**
15
+ * Build Agents row meta from Show toggles.
16
+ * `promptPreview` is async (host timeline); pass `…` while loading, or omit when empty/error.
17
+ */
14
18
  export function formatAgentMeta(
15
19
  item: AgentUsageItem,
16
20
  showFields: ReadonlySet<AgentShowField>,
17
21
  byId: Record<string, AgentStatusInfo> | undefined,
18
22
  locale: string,
23
+ promptPreview?: string | null,
19
24
  ): string | null {
20
25
  const parts: string[] = [];
21
26
  if (showFields.has("provider")) parts.push(providerLabel(item.provider));
@@ -25,6 +30,10 @@ export function formatAgentMeta(
25
30
  const at = agentUpdatedAt(item, byId);
26
31
  if (at) parts.push(formatActivityTime(at, locale));
27
32
  }
33
+ if (showFields.has("prompt")) {
34
+ const preview = promptPreview?.trim();
35
+ if (preview) parts.push(preview);
36
+ }
28
37
  if (parts.length === 0) return null;
29
38
  return parts.join(" · ");
30
39
  }
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { test } from "node:test";
3
3
  import { attentionKind } from "./constants.ts";
4
- import { loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
4
+ import { agentStatusInfo, applyAgentStatusUpdate, loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
5
5
 
6
6
  test("workspace status uses daemon placement project ID on every page and rejects other workspaces", async () => {
7
7
  let pages = 0;
@@ -43,3 +43,61 @@ test("pending questions survive a poll when catalog key differs from placement k
43
43
  const fallback = await loadWorkspaceAgentStatuses(paseo, workspace.id);
44
44
  assert.equal(fallback.waiting?.permissionCount, 1);
45
45
  });
46
+
47
+ test("agentStatusInfo maps parentAgentId and preserves it on partial pushes", () => {
48
+ const first = agentStatusInfo({ id: "child", workspaceId: "w", parentAgentId: "parent" });
49
+ assert.equal(first.parentAgentId, "parent");
50
+ const partial = agentStatusInfo(
51
+ { id: "child", workspaceId: "w", status: "running", pendingPermissions: [{}] },
52
+ first,
53
+ );
54
+ assert.equal(partial.parentAgentId, "parent");
55
+ assert.equal(partial.status, "running");
56
+ assert.equal(partial.permissionCount, 1);
57
+ const cleared = agentStatusInfo(
58
+ { id: "child", workspaceId: "w", parentAgentId: null },
59
+ partial,
60
+ );
61
+ assert.equal(cleared.parentAgentId, null);
62
+ });
63
+
64
+ test("agentStatusInfo falls back to paseo.parent-agent-id label when field is null", () => {
65
+ const fromLabel = agentStatusInfo({
66
+ id: "child",
67
+ workspaceId: "w",
68
+ parentAgentId: null,
69
+ labels: { "paseo.parent-agent-id": "e59c28e7-91f6-4571-b182-56c9b93116c6" },
70
+ });
71
+ assert.equal(fromLabel.parentAgentId, "e59c28e7-91f6-4571-b182-56c9b93116c6");
72
+ const prefersField = agentStatusInfo({
73
+ id: "child",
74
+ workspaceId: "w",
75
+ parentAgentId: "root",
76
+ labels: { "paseo.parent-agent-id": "other" },
77
+ });
78
+ assert.equal(prefersField.parentAgentId, "root");
79
+ });
80
+
81
+ test("applyAgentStatusUpdate marks remove as closed and merges upserts without workspaceId", () => {
82
+ const map = {
83
+ a: agentStatusInfo({ id: "a", workspaceId: "w", status: "idle" }),
84
+ b: agentStatusInfo({ id: "b", workspaceId: "w", status: "running", pendingPermissions: [{}] }),
85
+ };
86
+ applyAgentStatusUpdate(map, "w", { kind: "remove", agentId: "a" });
87
+ assert.equal(map.a.status, "closed");
88
+ assert.equal(map.a.permissionCount, 0);
89
+ applyAgentStatusUpdate(map, "w", {
90
+ kind: "upsert",
91
+ agent: { id: "b", status: "closed" },
92
+ });
93
+ assert.equal(map.b.status, "closed");
94
+ assert.equal(map.b.permissionCount, 1);
95
+ applyAgentStatusUpdate(map, "w", {
96
+ kind: "upsert",
97
+ agent: { id: "c", status: "idle" },
98
+ });
99
+ assert.equal(
100
+ (map as Record<string, ReturnType<typeof agentStatusInfo>>).c,
101
+ undefined,
102
+ );
103
+ });
@@ -14,6 +14,8 @@ export type HostAgentEntry = {
14
14
  requiresAttention?: boolean;
15
15
  attentionReason?: string | null;
16
16
  pendingPermissions?: ReadonlyArray<unknown>;
17
+ parentAgentId?: string | null;
18
+ labels?: Readonly<Record<string, string>>;
17
19
  };
18
20
  };
19
21
 
@@ -21,6 +23,16 @@ export type HostAgentUpdate =
21
23
  | { kind: "remove"; agentId: string }
22
24
  | { kind: "upsert"; agent: HostAgentEntry["agent"] };
23
25
 
26
+ /** Prefer first-class parentAgentId; fall back to legacy label (agent-crew / older snapshots). */
27
+ export const PARENT_AGENT_ID_LABEL = "paseo.parent-agent-id";
28
+
29
+ export function resolveParentAgentId(agent: HostAgentEntry["agent"]): string | null {
30
+ const firstClass = agent.parentAgentId;
31
+ if (typeof firstClass === "string" && firstClass.trim()) return firstClass.trim();
32
+ const legacy = agent.labels?.[PARENT_AGENT_ID_LABEL];
33
+ return typeof legacy === "string" && legacy.trim() ? legacy.trim() : null;
34
+ }
35
+
24
36
  type HostAgentsApi = {
25
37
  agents: {
26
38
  subscribe?: (handler: (update: HostAgentUpdate) => void) => () => void;
@@ -74,17 +86,62 @@ export function applyAgentStatusUpdate(
74
86
  map: Record<string, AgentStatusInfo>, workspaceId: string, update: HostAgentUpdate,
75
87
  ): void {
76
88
  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);
89
+ if (update.kind === "remove") {
90
+ // Keep the row as Closed so Lifecycle filters work until the next list poll.
91
+ const previous = map[id];
92
+ if (!previous) return;
93
+ map[id] = agentStatusInfo(
94
+ { id, workspaceId, status: "closed", updatedAt: previous.updatedAt ?? undefined },
95
+ previous,
96
+ );
97
+ return;
98
+ }
99
+ const agentWorkspaceId = update.agent.workspaceId;
100
+ if (agentWorkspaceId != null && agentWorkspaceId !== workspaceId) {
101
+ delete map[id];
102
+ return;
103
+ }
104
+ // Missing workspaceId: still merge when we already track the agent (043).
105
+ if (agentWorkspaceId == null && !(id in map)) return;
106
+ map[id] = agentStatusInfo(update.agent, map[id]);
79
107
  }
80
108
 
81
- export function agentStatusInfo(agent: HostAgentEntry["agent"]): AgentStatusInfo {
109
+ /** Map host agent → status; preserve prior attention fields when the push omits them. */
110
+ export function agentStatusInfo(
111
+ agent: HostAgentEntry["agent"],
112
+ previous?: AgentStatusInfo,
113
+ ): AgentStatusInfo {
114
+ const permissionCount =
115
+ agent.pendingPermissions !== undefined
116
+ ? agent.pendingPermissions.length
117
+ : (previous?.permissionCount ?? 0);
118
+ const requiresAttention =
119
+ agent.requiresAttention !== undefined
120
+ ? agent.requiresAttention === true
121
+ : (previous?.requiresAttention ?? false);
122
+ const attentionReason =
123
+ agent.attentionReason !== undefined
124
+ ? agent.attentionReason
125
+ : (previous?.attentionReason ?? null);
126
+ const parentSpecified =
127
+ agent.parentAgentId !== undefined ||
128
+ (agent.labels != null && PARENT_AGENT_ID_LABEL in agent.labels);
129
+ const parentAgentId = parentSpecified
130
+ ? resolveParentAgentId(agent)
131
+ : (previous?.parentAgentId ?? null);
82
132
  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,
133
+ rank: attentionRank({
134
+ status: agent.status,
135
+ requiresAttention,
136
+ attentionReason,
137
+ pendingPermissions: agent.pendingPermissions ??
138
+ (permissionCount > 0 ? Array.from({ length: permissionCount }) : undefined),
139
+ }),
140
+ updatedAt: agent.updatedAt ?? previous?.updatedAt ?? null,
141
+ status: agent.status ?? previous?.status ?? null,
142
+ permissionCount,
143
+ requiresAttention,
144
+ attentionReason,
145
+ parentAgentId,
89
146
  };
90
147
  }
@@ -1,14 +1,14 @@
1
- import { updateWorkspaceStatusCache } from "./status-cache.ts";
2
1
  import {
3
2
  type PluginWorkspacePanelProps,
4
3
  usePaseo,
5
4
  useRpc,
6
5
  useSettings,
7
- useWorkspace,
8
6
  } from "@getpaseo/plugin/client";
9
7
  import { useToast } from "@getpaseo/plugin/client/react-native";
10
8
  import { useQuery, useQueryClient } from "@tanstack/react-query";
11
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
+ import { useRegisterOpenAgent } from "../open-agent.ts";
11
+ import { useWorkspaceAgentStatuses } from "../use-workspace-agent-statuses.ts";
12
12
  import {
13
13
  ActivityIndicator,
14
14
  Dimensions,
@@ -37,6 +37,7 @@ import { useAppLanguage } from "../use-app-language.ts";
37
37
  import { useWorkspaceActivityRefresh } from "../use-agent-turn-end.ts";
38
38
  import { UsageStats } from "../usage-stats.tsx";
39
39
  import { AgentsSection } from "./agents-section.tsx";
40
+ import { WorkspaceAgentLiveStatusSync } from "./agent-live-status-sync.tsx";
40
41
  import {
41
42
  AGENT_HEADER_HEIGHT,
42
43
  GROUP_OPTIONS,
@@ -60,7 +61,6 @@ import {
60
61
  } from "./constants.ts";
61
62
  import { MenuOptionList, MenuSubTrigger } from "./display-menu.tsx";
62
63
  import { matchesAgentTitle } from "./filters.ts";
63
- import { loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
64
64
  import { RankSection } from "./rank-section.tsx";
65
65
  import { TerminalsSection, type TerminalListItem } from "./terminals-section.tsx";
66
66
 
@@ -106,6 +106,7 @@ export function WorkspaceActivityPanel({
106
106
  const toast = useToast();
107
107
  const queryClient = useQueryClient();
108
108
  const openAgent = navigation?.openAgent;
109
+ useRegisterOpenAgent(openAgent);
109
110
  const rootRef = useRef<View>(null);
110
111
  const triggerRef = useRef<View>(null);
111
112
 
@@ -167,25 +168,7 @@ export function WorkspaceActivityPanel({
167
168
  queryFn: () => hostInfoRpc({}),
168
169
  });
169
170
 
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
- );
177
- const statuses = useQuery({
178
- refetchInterval: 15_000,
179
- retry: false,
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]);
171
+ const statuses = useWorkspaceAgentStatuses(workspaceId);
189
172
 
190
173
  useWorkspaceActivityRefresh(workspaceId, () => {
191
174
  void queryClient.invalidateQueries({
@@ -201,6 +184,10 @@ export function WorkspaceActivityPanel({
201
184
  });
202
185
 
203
186
  const agentItems = agents.data?.items ?? [];
187
+ const liveStatusAgentIds = useMemo(
188
+ () => agentItems.map((item) => item.agentId),
189
+ [agentItems],
190
+ );
204
191
  const visibleAgentItems = useMemo(() => {
205
192
  const byId = statuses.data;
206
193
  const filtered = agentItems
@@ -406,6 +393,27 @@ export function WorkspaceActivityPanel({
406
393
  justifyContent: "center" as const,
407
394
  backgroundColor: theme.colors.surface0,
408
395
  },
396
+ subAgentBadge: {
397
+ position: "absolute" as const,
398
+ right: -5,
399
+ bottom: -5,
400
+ minWidth: 14,
401
+ height: 14,
402
+ paddingHorizontal: 3,
403
+ borderRadius: 7,
404
+ alignItems: "center" as const,
405
+ justifyContent: "center" as const,
406
+ backgroundColor: theme.colors.surface0,
407
+ borderWidth: 1,
408
+ borderColor: theme.colors.border,
409
+ },
410
+ subAgentBadgeText: {
411
+ color: theme.colors.foregroundMuted,
412
+ fontSize: 9,
413
+ fontWeight: "700" as const,
414
+ fontVariant: ["tabular-nums" as const],
415
+ lineHeight: 11,
416
+ },
409
417
  listMain: {
410
418
  flex: 1,
411
419
  minWidth: 0,
@@ -830,14 +838,21 @@ export function WorkspaceActivityPanel({
830
838
  ) : null}
831
839
 
832
840
  {showAgents ? (
833
- <AgentsSection
841
+ <>
842
+ <WorkspaceAgentLiveStatusSync
843
+ agentIds={liveStatusAgentIds}
844
+ workspaceId={workspaceId}
845
+ />
846
+ <AgentsSection
834
847
  theme={theme}
835
848
  styles={styles}
836
849
  locale={locale}
837
850
  agentGroup={agentGroup}
838
851
  agentShowFields={agentShowFields}
839
852
  statuses={statuses.data}
853
+ agentItems={agentItems}
840
854
  visibleAgentItems={visibleAgentItems}
855
+ statusFilters={agentStatusFilters}
841
856
  statusFiltersEmpty={
842
857
  agentStatusFilters.size === 0 || agentLifecycleFilters.size === 0
843
858
  }
@@ -855,6 +870,7 @@ export function WorkspaceActivityPanel({
855
870
  onUnarchive={(item) => void unarchiveAgent(item)}
856
871
  resetKey={workspaceId}
857
872
  />
873
+ </>
858
874
  ) : null}
859
875
 
860
876
  {showTerminals ? (