@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,79 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { listAllAgentPages } from "../shared/list-agent-pages.ts";
3
+
4
+ type AgentsApi = PluginClientContext["paseo"]["agents"];
5
+ type Update = Parameters<Parameters<AgentsApi["subscribe"]>[0]>[0];
6
+ type Agent = Extract<Update, { kind: "upsert" }>["agent"];
7
+
8
+ /** 0.8 has one shared directory slot. Plain paged reads own our fallback, never that slot. */
9
+ export function watchPillDirectory(
10
+ agents: AgentsApi,
11
+ onAgent: (agent: Agent) => void,
12
+ onRemove: (agentId: string) => void,
13
+ intervalMs = 15_000,
14
+ onPolled?: (agent: Agent) => void,
15
+ ): () => void {
16
+ let disposed = false;
17
+ let timer: ReturnType<typeof setTimeout> | undefined;
18
+ let pending: Update[] | null = null;
19
+ let known = new Set<string>();
20
+ const versions = new Map<string, string>();
21
+ function publish(agent: Agent) {
22
+ const version = JSON.stringify([agent.workspaceId, agent.status, agent.updatedAt,
23
+ agent.lastUserMessageAt, agent.activeTurn?.turnId]);
24
+ if (versions.get(agent.id) === version) return;
25
+ versions.set(agent.id, version);
26
+ onAgent(agent);
27
+ }
28
+ function remove(id: string) {
29
+ versions.delete(id);
30
+ onRemove(id);
31
+ }
32
+ function apply(update: Update) {
33
+ if (update.kind === "remove") {
34
+ known.delete(update.agentId);
35
+ remove(update.agentId);
36
+ } else {
37
+ known.add(update.agent.id);
38
+ publish(update.agent);
39
+ }
40
+ }
41
+ // Opportunistic acceleration only; correctness does not depend on host observation.
42
+ const unsubscribe = agents.subscribe((update) => {
43
+ if (disposed) return;
44
+ pending?.push(update);
45
+ apply(update);
46
+ });
47
+ async function sync() {
48
+ pending = [];
49
+ try {
50
+ const entries = await listAllAgentPages((cursor) => agents.list({
51
+ page: { limit: 200, ...(cursor ? { cursor } : {}) },
52
+ }));
53
+ if (disposed) return;
54
+ const snapshot = new Map(entries.map(({ agent }) => [agent.id, agent]));
55
+ // Pushes received during pagination are newer than its snapshot.
56
+ for (const update of pending) {
57
+ if (update.kind === "remove") snapshot.delete(update.agentId);
58
+ else snapshot.set(update.agent.id, update.agent);
59
+ }
60
+ for (const id of known) if (!snapshot.has(id)) remove(id);
61
+ known = new Set(snapshot.keys());
62
+ for (const agent of snapshot.values()) {
63
+ publish(agent);
64
+ onPolled?.(agent);
65
+ }
66
+ } catch (error) {
67
+ if (!disposed) console.error("[activity] could not sync composer pills", error);
68
+ } finally {
69
+ pending = null;
70
+ if (!disposed) timer = setTimeout(() => void sync(), intervalMs);
71
+ }
72
+ }
73
+ void sync();
74
+ return () => {
75
+ disposed = true;
76
+ unsubscribe();
77
+ clearTimeout(timer);
78
+ };
79
+ }
package/client/pill.tsx CHANGED
@@ -1,3 +1,6 @@
1
+ import { createHiddenPillRecheck } from "./hidden-pill-recheck.ts";
2
+ import { writePillDataCache } from "./pill-data-cache.ts";
3
+ import { watchPillDirectory } from "./pill-directory.ts";
1
4
  import {
2
5
  type PluginButtonContentProps,
3
6
  type PluginButtonIconProps,
@@ -6,7 +9,7 @@ import {
6
9
  } from "@getpaseo/plugin/client";
7
10
  import { Icon } from "@getpaseo/plugin/client/react-native";
8
11
  import { useEffect, useRef } from "react";
9
- import { formatUsagePillLabel } from "../shared/usage.ts";
12
+ import { formatUsagePillLabel, usageSkillsByNameRpc, usageMcpByToolRpc } from "../shared/usage.ts";
10
13
  import { useUsagePillData, clearPillDataCache } from "./usage-query.tsx";
11
14
  import { UsagePopover, type SkillDetail } from "./usage-popover.tsx";
12
15
  import { requestOpenSkillInPanel } from "./pending-skill.ts";
@@ -23,6 +26,7 @@ const EMPTY_GRACE_MS_RECHECK = 4_000;
23
26
 
24
27
  type PillEntry = {
25
28
  registration?: PluginButtonRegistration;
29
+ recheck?: () => Promise<void>;
26
30
  /** Host unmounted the icon after a settled empty hide. */
27
31
  hidden: boolean;
28
32
  /** Already completed one empty grace → hide cycle for this agent. */
@@ -161,6 +165,16 @@ export function contributePills(client: PluginClientContext) {
161
165
  },
162
166
  });
163
167
  pills.set(agentId, entry);
168
+ entry.recheck = createHiddenPillRecheck(async () => {
169
+ const [skills, mcp] = await Promise.all([
170
+ client.rpc(usageSkillsByNameRpc, { agentId }),
171
+ client.rpc(usageMcpByToolRpc, { agentId }),
172
+ ]);
173
+ return { skills: skills.items, mcpTools: mcp.items };
174
+ }, () => pills.get(agentId) === entry && entry.hidden, (data) => {
175
+ writePillDataCache(agentId, data);
176
+ reviveHiddenPill(agentId);
177
+ });
164
178
  }
165
179
 
166
180
  function removePill(agentId: string) {
@@ -177,32 +191,18 @@ export function contributePills(client: PluginClientContext) {
177
191
  entry.registration.update({ label: TITLE, visible: true });
178
192
  }
179
193
 
180
- const unsubscribe = client.paseo.agents.subscribe((update) => {
181
- if (update.kind === "remove") {
182
- removePill(update.agentId);
183
- return;
184
- }
185
- const { id, workspaceId, status } = update.agent;
194
+ const unsubscribe = watchPillDirectory(client.paseo.agents, (agent) => {
195
+ const { id, workspaceId, status } = agent;
186
196
  if (!workspaceId) return;
187
- if (pills.has(id)) {
188
- // turn_ended ingest races with idle; remount hidden pills so they can catch up.
189
- if (status === "idle") reviveHiddenPill(id);
190
- return;
191
- }
192
197
  addPill(id, workspaceId);
198
+ // A read/push is a refresh hint, not proof of turn completion.
199
+ if (status === "idle") reviveHiddenPill(id);
200
+ }, removePill, 15_000, (agent) => {
201
+ // Ingest can finish after the empty grace period without another agent update.
202
+ // Keep the fallback query, but only make the pill visible when data exists.
203
+ if (agent.status === "idle") void pills.get(agent.id)?.recheck?.();
193
204
  });
194
205
 
195
- client.paseo.agents
196
- .list()
197
- .then((result) => {
198
- result.entries.forEach(({ agent }) => {
199
- if (agent.workspaceId) addPill(agent.id, agent.workspaceId);
200
- });
201
- })
202
- .catch((error: unknown) => {
203
- console.error("[activity] could not seed composer pills", error);
204
- });
205
-
206
206
  return () => {
207
207
  unsubscribe();
208
208
  pills.forEach((entry) => entry.registration?.remove());
@@ -17,7 +17,8 @@ import {
17
17
  import {
18
18
  usageReadSkillRpc,
19
19
  } from "../shared/usage.ts";
20
- import { formatDayTime, formatDisplayName } from "../shared/format.ts";
20
+ import { formatDisplayName } from "../shared/format.ts";
21
+ import { FormattedTime } from "./formatted-time.tsx";
21
22
  import { useUsagePillData } from "./usage-query.tsx";
22
23
 
23
24
  const MONO = Platform.select({ ios: "Menlo", default: "monospace" });
@@ -111,28 +112,25 @@ function UsagePopoverAgent(
111
112
  minWidth: compact ? undefined : 300,
112
113
  maxWidth: compact ? undefined : 380,
113
114
  },
114
- rangeBar: {
115
+ sectionHeaderRow: {
115
116
  flexDirection: "row" as const,
116
117
  alignItems: "center" as const,
117
- alignSelf: "flex-start" as const,
118
- gap: 20,
119
- },
120
- rangeSegment: {
121
- paddingVertical: 8,
122
- },
123
- rangeSegmentActive: {
124
- borderBottomWidth: 1,
125
- borderBottomColor: theme.colors.foreground,
126
- },
127
- chipText: {
128
- color: theme.colors.foregroundMuted,
129
- fontSize: 12,
130
- fontWeight: "500" as const,
118
+ justifyContent: "space-between" as const,
119
+ gap: 8,
131
120
  },
132
- chipTextActive: {
121
+ sectionTitle: {
133
122
  color: theme.colors.foreground,
134
- fontSize: 12,
123
+ fontSize: 14,
135
124
  fontWeight: "600" as const,
125
+ flexShrink: 1,
126
+ },
127
+ titleAction: {
128
+ width: 24,
129
+ height: 24,
130
+ alignItems: "center" as const,
131
+ justifyContent: "center" as const,
132
+ borderRadius: 6,
133
+ flexShrink: 0,
136
134
  },
137
135
  list: {
138
136
  gap: 0,
@@ -159,11 +157,6 @@ function UsagePopoverAgent(
159
157
  fontSize: 13,
160
158
  fontWeight: "500" as const,
161
159
  },
162
- rowLink: {
163
- color: theme.colors.foreground,
164
- fontSize: 13,
165
- fontWeight: "500" as const,
166
- },
167
160
  rowMeta: {
168
161
  color: theme.colors.foregroundMuted,
169
162
  fontSize: 11,
@@ -199,17 +192,16 @@ function UsagePopoverAgent(
199
192
  fontWeight: "500" as const,
200
193
  },
201
194
  panelButton: {
202
- paddingHorizontal: 10,
203
- paddingVertical: 8,
204
- borderRadius: 8,
205
- backgroundColor: theme.colors.surface2,
206
- flexDirection: "row" as const,
195
+ width: 24,
196
+ height: 24,
207
197
  alignItems: "center" as const,
208
- gap: 6,
198
+ justifyContent: "center" as const,
199
+ borderRadius: 6,
200
+ flexShrink: 0,
209
201
  },
210
202
  title: {
211
203
  color: theme.colors.foreground,
212
- fontSize: compact ? 15 : 16,
204
+ fontSize: 14,
213
205
  fontWeight: "600" as const,
214
206
  flexShrink: 1,
215
207
  },
@@ -226,11 +218,13 @@ function UsagePopoverAgent(
226
218
  [theme, compact],
227
219
  );
228
220
 
229
- // Cached pill data (QueryClient or module cache) must paint immediately; only
230
- // spin when we have nothing to show yet.
231
221
  const loading = !usage.data && usage.isLoading;
232
222
  const error = usage.error;
233
- const showTabs = skillItems.length > 0 && mcpItems.length > 0;
223
+ const showToggle = skillItems.length > 0 && mcpItems.length > 0;
224
+ const toggleAction =
225
+ tab === "skills"
226
+ ? { icon: "Plug" as const, accessibilityLabel: "Show MCP", next: "mcp" as const }
227
+ : { icon: "Sparkles" as const, accessibilityLabel: "Show skills", next: "skills" as const };
234
228
 
235
229
  if (skillDetail) {
236
230
  return (
@@ -248,14 +242,14 @@ function UsagePopoverAgent(
248
242
  <Pressable
249
243
  accessibilityRole="button"
250
244
  accessibilityLabel="Open SKILL.md in panel"
245
+ hitSlop={8}
251
246
  style={styles.panelButton}
252
247
  onPress={() => {
253
248
  openSkillInPanel(skillDetail);
254
249
  close();
255
250
  }}
256
251
  >
257
- <Icon name="ArrowUpRight" size={14} color={theme.colors.foregroundMuted} />
258
- <Text style={styles.back}>Open in tab</Text>
252
+ <Icon name="ArrowUpRight" size={16} color={theme.colors.foregroundMuted} />
259
253
  </Pressable>
260
254
  ) : null}
261
255
  </View>
@@ -277,33 +271,24 @@ function UsagePopoverAgent(
277
271
 
278
272
  return (
279
273
  <View style={styles.root}>
280
- {!compact ? (
281
- <View style={{ gap: 4 }}>
282
- <Text style={styles.title}>Activity</Text>
283
- <Text style={styles.rowMeta}>Current conversation</Text>
284
- </View>
285
- ) : null}
286
- {showTabs ? (
287
- <View style={styles.rangeBar}>
288
- {(
289
- [
290
- ["skills", "Skills"],
291
- ["mcp", "MCP"],
292
- ] as const
293
- ).map(([id, label]) => {
294
- const active = tab === id;
295
- return (
296
- <Pressable
297
- key={id}
298
- accessibilityRole="tab"
299
- accessibilityState={{ selected: active }}
300
- onPress={() => setTab(id)}
301
- style={[styles.rangeSegment, active ? styles.rangeSegmentActive : null]}
302
- >
303
- <Text style={active ? styles.chipTextActive : styles.chipText}>{label}</Text>
304
- </Pressable>
305
- );
306
- })}
274
+ {tab && (skillItems.length > 0 || mcpItems.length > 0) ? (
275
+ <View style={styles.sectionHeaderRow}>
276
+ <Text style={styles.sectionTitle}>{tab === "skills" ? "Skills" : "MCP"}</Text>
277
+ {showToggle ? (
278
+ <Pressable
279
+ accessibilityRole="button"
280
+ accessibilityLabel={toggleAction.accessibilityLabel}
281
+ hitSlop={8}
282
+ onPress={() => setTab(toggleAction.next)}
283
+ style={styles.titleAction}
284
+ >
285
+ <Icon
286
+ name={toggleAction.icon}
287
+ size={16}
288
+ color={theme.colors.foregroundMuted}
289
+ />
290
+ </Pressable>
291
+ ) : null}
307
292
  </View>
308
293
  ) : null}
309
294
 
@@ -322,33 +307,39 @@ function UsagePopoverAgent(
322
307
  <View style={styles.list}>
323
308
  {skillItems.map((item, index) => {
324
309
  const name = formatDisplayName(item.skillName);
325
- const title = item.skillPath ? (
326
- <Pressable
327
- accessibilityRole="link"
328
- accessibilityLabel={`Open ${name} SKILL.md`}
329
- onPress={() =>
330
- setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
331
- }
332
- >
333
- <Text style={styles.rowLink} numberOfLines={1}>
334
- {name}
335
- </Text>
336
- </Pressable>
337
- ) : (
338
- <Text style={styles.rowTitle} numberOfLines={1}>
339
- {name}
340
- </Text>
341
- );
342
- return (
343
- <View key={item.skillName} style={[styles.row, index === 0 ? styles.rowFirst : null]}>
310
+ const rowStyle = [styles.row, index === 0 ? styles.rowFirst : null];
311
+ const content = (
312
+ <>
344
313
  <Icon name="Sparkles" size={16} color={theme.colors.foregroundMuted} />
345
314
  <View style={styles.rowMain}>
346
- {title}
315
+ <Text style={styles.rowTitle} numberOfLines={1}>
316
+ {name}
317
+ </Text>
347
318
  {item.lastUsedAt ? (
348
- <Text style={styles.rowMeta}>{formatDayTime(item.lastUsedAt)}</Text>
319
+ <FormattedTime iso={item.lastUsedAt} style={styles.rowMeta} />
349
320
  ) : null}
350
321
  </View>
351
322
  <CountBadge value={item.total} styles={styles} />
323
+ </>
324
+ );
325
+ if (item.skillPath) {
326
+ return (
327
+ <Pressable
328
+ key={item.skillName}
329
+ accessibilityRole="link"
330
+ accessibilityLabel={`Open ${name} SKILL.md`}
331
+ onPress={() =>
332
+ setSkillDetail({ skillName: item.skillName, path: item.skillPath! })
333
+ }
334
+ style={rowStyle}
335
+ >
336
+ {content}
337
+ </Pressable>
338
+ );
339
+ }
340
+ return (
341
+ <View key={item.skillName} style={rowStyle}>
342
+ {content}
352
343
  </View>
353
344
  );
354
345
  })}
@@ -370,7 +361,7 @@ function UsagePopoverAgent(
370
361
  {item.failures > 0 ? (
371
362
  <Text style={styles.rowMeta}>{item.failures} failed</Text>
372
363
  ) : item.lastUsedAt ? (
373
- <Text style={styles.rowMeta}>{formatDayTime(item.lastUsedAt)}</Text>
364
+ <FormattedTime iso={item.lastUsedAt} style={styles.rowMeta} />
374
365
  ) : null}
375
366
  </View>
376
367
  <CountBadge value={item.count} styles={styles} />
@@ -1,5 +1,5 @@
1
1
  import { useRpc } from "@getpaseo/plugin/client";
2
- import { useQuery } from "@tanstack/react-query";
2
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
3
3
  import {
4
4
  usageMcpByToolRpc,
5
5
  usageSkillsByNameRpc,
@@ -10,17 +10,22 @@ import {
10
10
  writePillDataCache,
11
11
  type UsagePillData,
12
12
  } from "./pill-data-cache.ts";
13
+ import { useAgentTurnEnd } from "./use-agent-turn-end.ts";
13
14
 
14
15
  export type { UsagePillData } from "./pill-data-cache.ts";
15
16
  export { __setPillDataCacheForTests, clearPillDataCache } from "./pill-data-cache.ts";
16
17
 
17
- /** Poll while empty so mid-turn mount can see post-turn_ended rows before hide. */
18
- const EMPTY_REFETCH_MS = 1_500;
18
+ /** Fallback poll while empty; host turn-end events drive the fast path. */
19
+ const EMPTY_REFETCH_MS = 5_000;
19
20
 
20
21
  /** Current-agent skills/mcp breakdown for the composer pill (no summary — unused in UI). */
21
22
  export function useUsagePillData(agentId: string) {
22
23
  const skillsRpc = useRpc(usageSkillsByNameRpc);
23
24
  const mcpRpc = useRpc(usageMcpByToolRpc);
25
+ const queryClient = useQueryClient();
26
+ useAgentTurnEnd({ agentId }, () => {
27
+ void queryClient.invalidateQueries({ queryKey: ["activity", "pill", "agent", agentId] });
28
+ });
24
29
  return useQuery({
25
30
  queryKey: ["activity", "pill", "agent", agentId],
26
31
  queryFn: async () => {
@@ -11,8 +11,8 @@ export function UsageStats({ items, colors, compact, dense }: {
11
11
  <View style={{ flexDirection: "row", flexWrap: "wrap", borderWidth: 1, borderColor: colors.border, borderRadius: 20, paddingVertical: dense ? 6 : compact ? 8 : 18, rowGap: dense ? 10 : 16 }}>
12
12
  {items.map((item, index) => (
13
13
  <View key={item.label} style={{ flexGrow: 1, flexBasis: dense ? 84 : compact ? 100 : 120, minWidth: 0, alignItems: "center", paddingHorizontal: dense ? 8 : 12, paddingVertical: dense ? 2 : 4, gap: dense ? 4 : 6, borderLeftWidth: index === 0 || compact ? 0 : 1, borderLeftColor: colors.border }}>
14
- <Text style={{ color: colors.foreground, fontSize: dense ? 17 : compact ? 20 : 24, fontWeight: "500", fontVariant: ["tabular-nums"] }}>{item.value}</Text>
15
- <Text style={{ color: colors.foregroundMuted, fontSize: dense ? 11 : compact ? 12 : 14 }}>{item.label}</Text>
14
+ <Text style={{ color: colors.foreground, fontSize: 18, fontWeight: "500", fontVariant: ["tabular-nums"] }}>{item.value}</Text>
15
+ <Text style={{ color: colors.foregroundMuted, fontSize: 12 }}>{item.label}</Text>
16
16
  </View>
17
17
  ))}
18
18
  </View>
@@ -0,0 +1,69 @@
1
+ import { usePaseo } from "@getpaseo/plugin/client";
2
+ import { useEffect, useRef } from "react";
3
+
4
+ const TURN_END_DEBOUNCE_MS = 300;
5
+ const INGEST_SETTLE_MS = 2_000;
6
+
7
+ type AgentTurnEndScope = {
8
+ agentId?: string;
9
+ workspaceId?: string;
10
+ };
11
+
12
+ /** Shared debounce/ingest settle scheduling; callers choose the signal explicitly. */
13
+ function useActivityRefresh(scope: AgentTurnEndScope, onTurnEnd: () => void): void {
14
+ const paseo = usePaseo();
15
+ const { agentId, workspaceId } = scope;
16
+ const callbackRef = useRef(onTurnEnd);
17
+
18
+ useEffect(() => {
19
+ callbackRef.current = onTurnEnd;
20
+ });
21
+
22
+ useEffect(() => {
23
+ let debounce: ReturnType<typeof setTimeout> | null = null;
24
+ let settle: ReturnType<typeof setTimeout> | null = null;
25
+ const schedule = () => {
26
+ if (debounce != null) clearTimeout(debounce);
27
+ if (settle != null) clearTimeout(settle);
28
+ debounce = setTimeout(() => {
29
+ debounce = null;
30
+ callbackRef.current();
31
+ }, TURN_END_DEBOUNCE_MS);
32
+ settle = setTimeout(() => {
33
+ settle = null;
34
+ callbackRef.current();
35
+ }, INGEST_SETTLE_MS);
36
+ };
37
+ const unsubscribe = agentId != null
38
+ ? paseo.agents.ref(agentId).timeline.subscribe(({ event }) => {
39
+ if (["turn_completed", "turn_failed", "turn_canceled", "replacement"].includes(event.type)) schedule();
40
+ })
41
+ : paseo.agents.subscribe((update) => {
42
+ // Workspace-wide hint only. The 15s query poll owns completeness.
43
+ if (update.kind !== "upsert") return;
44
+ const agent = update.agent;
45
+ if (agent.workspaceId !== workspaceId) return;
46
+ if (agent.status !== "running" && agent.status !== "initializing") schedule();
47
+ });
48
+ if ("ready" in unsubscribe) {
49
+ void (unsubscribe.ready as Promise<void>).catch((error: unknown) => {
50
+ console.error("[activity] timeline observation failed; polling remains active", error);
51
+ });
52
+ }
53
+ return () => {
54
+ unsubscribe();
55
+ if (debounce != null) clearTimeout(debounce);
56
+ if (settle != null) clearTimeout(settle);
57
+ };
58
+ }, [paseo, agentId, workspaceId]);
59
+ }
60
+
61
+ /** Actual turn terminal events; directory status does not imply completion. */
62
+ export function useAgentTurnEnd(scope: { agentId: string }, onTurnEnd: () => void): void {
63
+ useActivityRefresh(scope, onTurnEnd);
64
+ }
65
+
66
+ /** Best-effort directory hint, never a turn-end signal. */
67
+ export function useWorkspaceActivityRefresh(workspaceId: string, refresh: () => void): void {
68
+ useActivityRefresh({ workspaceId }, refresh);
69
+ }
@@ -9,15 +9,20 @@ import {
9
9
  type TextStyle,
10
10
  type ViewStyle,
11
11
  } from "react-native";
12
- import type { WorkspaceTheme } from "./constants.ts";
12
+ import type { AgentAttentionKind, WorkspaceTheme } from "./constants.ts";
13
+ import { RunningIndicator } from "./running-indicator.tsx";
13
14
 
14
15
  export type AgentRowStyles = {
15
16
  agentListRow: ViewStyle;
17
+ agentIconWrap: ViewStyle;
18
+ runningBadge: ViewStyle;
16
19
  listMain: ViewStyle;
17
20
  listLink: TextStyle;
18
21
  listTitle: TextStyle;
19
22
  listMeta: TextStyle;
20
23
  titleAction: ViewStyle;
24
+ permissionBadge: ViewStyle;
25
+ permissionBadgeText: TextStyle;
21
26
  };
22
27
 
23
28
  export function AgentRow({
@@ -25,6 +30,9 @@ export function AgentRow({
25
30
  archived,
26
31
  canOpen,
27
32
  meta,
33
+ permissionCount,
34
+ attentionKind,
35
+ running,
28
36
  busy,
29
37
  actionDisabled,
30
38
  theme,
@@ -36,6 +44,9 @@ export function AgentRow({
36
44
  archived: boolean;
37
45
  canOpen: boolean;
38
46
  meta: string | null;
47
+ permissionCount: number;
48
+ attentionKind: AgentAttentionKind;
49
+ running: boolean;
39
50
  busy: boolean;
40
51
  actionDisabled: boolean;
41
52
  theme: WorkspaceTheme;
@@ -55,13 +66,39 @@ export function AgentRow({
55
66
  } as object)
56
67
  : null;
57
68
 
69
+ const botColor =
70
+ !archived && attentionKind === "error"
71
+ ? theme.colors.statusDanger
72
+ : !archived && attentionKind === "permission"
73
+ ? theme.colors.statusWarning
74
+ : !archived && attentionKind === "finished"
75
+ ? theme.colors.statusSuccess
76
+ : theme.colors.foregroundMuted;
77
+ const stateLabels: string[] = [];
78
+ if (!archived && running) stateLabels.push("running");
79
+ if (permissionCount > 0) {
80
+ stateLabels.push(
81
+ permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`,
82
+ );
83
+ }
84
+ if (!archived && attentionKind === "error") stateLabels.push("failed");
85
+ if (!archived && attentionKind === "finished") stateLabels.push("turn finished, unread");
86
+ const stateSuffix = stateLabels.length > 0 ? `, ${stateLabels.join(", ")}` : "";
87
+
58
88
  const body = (
59
89
  <>
60
- <Icon
61
- name={archived ? "BotOff" : "Bot"}
62
- size={18}
63
- color={theme.colors.foregroundMuted}
64
- />
90
+ <View style={styles.agentIconWrap}>
91
+ <Icon
92
+ name={archived ? "BotOff" : "Bot"}
93
+ size={18}
94
+ color={botColor}
95
+ />
96
+ {running && !archived ? (
97
+ <View style={styles.runningBadge}>
98
+ <RunningIndicator theme={theme} />
99
+ </View>
100
+ ) : null}
101
+ </View>
65
102
  <View style={styles.listMain}>
66
103
  <Text style={canOpen ? styles.listLink : styles.listTitle} numberOfLines={1}>
67
104
  {label}
@@ -72,6 +109,19 @@ export function AgentRow({
72
109
  </Text>
73
110
  ) : null}
74
111
  </View>
112
+ {permissionCount > 0 ? (
113
+ <View
114
+ accessibilityLabel={
115
+ permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`
116
+ }
117
+ style={styles.permissionBadge}
118
+ >
119
+ <Icon name="ShieldAlert" size={12} color={theme.colors.statusWarning} />
120
+ {permissionCount > 1 ? (
121
+ <Text style={styles.permissionBadgeText}>{permissionCount}</Text>
122
+ ) : null}
123
+ </View>
124
+ ) : null}
75
125
  <Pressable
76
126
  accessibilityRole="button"
77
127
  accessibilityLabel={archived ? `Unarchive ${label}` : `Archive ${label}`}
@@ -99,7 +149,7 @@ export function AgentRow({
99
149
  return (
100
150
  <Pressable
101
151
  accessibilityRole="link"
102
- accessibilityLabel={`Open conversation ${label}`}
152
+ accessibilityLabel={`Open conversation ${label}${stateSuffix}`}
103
153
  onPress={onOpen}
104
154
  style={styles.agentListRow}
105
155
  {...hoverProps}
@@ -13,6 +13,8 @@ import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
13
13
  import { AgentRow, type AgentRowStyles } from "./agent-row.tsx";
14
14
  import {
15
15
  AGENT_PAGE_SIZE,
16
+ attentionKind,
17
+ isAgentRunning,
16
18
  SEARCH_ANIM_MS,
17
19
  SEARCH_TITLE_GAP,
18
20
  type AgentGroup,
@@ -168,6 +170,8 @@ export function AgentsSection({
168
170
  const archived = item.archivedAt != null;
169
171
  const canOpen = openAgent != null && !archived;
170
172
  const meta = formatAgentMeta(item, agentShowFields, statuses, locale);
173
+ const statusInfo = statuses?.[item.agentId];
174
+ const permissionCount = statusInfo?.permissionCount ?? 0;
171
175
  const busy = busyAgentId === item.agentId;
172
176
  return (
173
177
  <AgentRow
@@ -176,6 +180,9 @@ export function AgentsSection({
176
180
  archived={archived}
177
181
  canOpen={canOpen}
178
182
  meta={meta}
183
+ permissionCount={permissionCount}
184
+ attentionKind={attentionKind(statusInfo)}
185
+ running={isAgentRunning(statusInfo)}
179
186
  busy={busy}
180
187
  actionDisabled={busy || busyAgentId != null}
181
188
  theme={theme}