@koinzhang/paseo-plugin-activity 0.3.0 → 0.5.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 +42 -2
  2. package/README.md +7 -6
  3. package/client/agent-directory.test.ts +191 -0
  4. package/client/agent-directory.ts +150 -0
  5. package/client/attention-agents.test.ts +94 -0
  6. package/client/attention-agents.ts +67 -0
  7. package/client/attention-pill.tsx +166 -0
  8. package/client/attention-popover.tsx +161 -0
  9. package/client/attention-status-store.ts +47 -0
  10. package/client/global-surface.tsx +3 -1
  11. package/client/latest-user-message.test.ts +34 -0
  12. package/client/latest-user-message.ts +96 -0
  13. package/client/open-agent.ts +32 -0
  14. package/client/panel.tsx +2 -0
  15. package/client/pill-directory.ts +20 -68
  16. package/client/use-agent-turn-end.ts +23 -3
  17. package/client/use-latest-user-message.ts +15 -0
  18. package/client/use-workspace-agent-statuses.ts +23 -0
  19. package/client/workspace/agent-row.tsx +49 -22
  20. package/client/workspace/agents-section.tsx +90 -22
  21. package/client/workspace/constants.test.ts +66 -0
  22. package/client/workspace/constants.ts +39 -1
  23. package/client/workspace/filters.test.ts +59 -0
  24. package/client/workspace/filters.ts +9 -0
  25. package/client/workspace/host-archive-sync.test.ts +46 -0
  26. package/client/workspace/host-archive-sync.ts +15 -0
  27. package/client/workspace/list-host-agents.test.ts +44 -38
  28. package/client/workspace/list-host-agents.ts +60 -57
  29. package/client/workspace/panel.tsx +43 -26
  30. package/index.client.tsx +7 -1
  31. package/package.json +3 -3
  32. package/paseo-plugin.json +1 -1
  33. package/shared/explorer-agent-display.ts +1 -1
  34. package/shared/usage.test.ts +8 -2
  35. package/shared/usage.ts +7 -0
  36. package/client/pill-directory.test.ts +0 -92
  37. package/client/workspace/status-cache.test.ts +0 -62
  38. package/client/workspace/status-cache.ts +0 -19
@@ -1,5 +1,6 @@
1
1
  import { usePaseo } from "@getpaseo/plugin/client";
2
2
  import { useEffect, useRef } from "react";
3
+ import { watchAgentDirectory } from "./agent-directory.ts";
3
4
 
4
5
  const TURN_END_DEBOUNCE_MS = 300;
5
6
  const INGEST_SETTLE_MS = 2_000;
@@ -36,11 +37,30 @@ function useActivityRefresh(scope: AgentTurnEndScope, onTurnEnd: () => void): vo
36
37
  };
37
38
  const unsubscribe = agentId != null
38
39
  ? paseo.agents.ref(agentId).timeline.subscribe(({ event }) => {
39
- if (["turn_completed", "turn_failed", "turn_canceled", "replacement"].includes(event.type)) schedule();
40
+ if (event.type === "subscription_restored") {
41
+ // Live-only after reconnect; refresh in case a turn ended while offline.
42
+ schedule();
43
+ return;
44
+ }
45
+ if (event.type === "error") {
46
+ console.error(
47
+ "[activity] timeline observation stopped; polling remains active",
48
+ "error" in event ? event.error : event,
49
+ );
50
+ return;
51
+ }
52
+ if (["turn_completed", "turn_failed", "turn_canceled", "replacement"].includes(event.type)) {
53
+ schedule();
54
+ }
40
55
  })
41
- : paseo.agents.subscribe((update) => {
56
+ : watchAgentDirectory(paseo.agents, (_snapshot, update) => {
42
57
  // Workspace-wide hint only. The 15s query poll owns completeness.
43
- if (update.kind !== "upsert") return;
58
+ // The surface owns its API observation, independently of the entry.
59
+ if (!update) { schedule(); return; }
60
+ if (update.kind === "remove") {
61
+ schedule();
62
+ return;
63
+ }
44
64
  const agent = update.agent;
45
65
  if (agent.workspaceId !== workspaceId) return;
46
66
  if (agent.status !== "running" && agent.status !== "initializing") schedule();
@@ -0,0 +1,15 @@
1
+ import { usePaseo } from "@getpaseo/plugin/client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { fetchLatestUserMessagePreview } from "./latest-user-message.ts";
4
+
5
+ /** Latest user prompt preview for an agent (host timeline tail; ephemeral). */
6
+ export function useLatestUserMessagePreview(agentId: string, enabled = true) {
7
+ const paseo = usePaseo();
8
+ return useQuery({
9
+ queryKey: ["activity", "latest-user-message", agentId],
10
+ queryFn: () => fetchLatestUserMessagePreview(paseo, agentId),
11
+ enabled: enabled && agentId.length > 0,
12
+ staleTime: 30_000,
13
+ retry: false,
14
+ });
15
+ }
@@ -0,0 +1,23 @@
1
+ import { usePaseo } from "@getpaseo/plugin/client";
2
+ import { useEffect, useState } from "react";
3
+ import { watchAgentDirectory } from "./agent-directory.ts";
4
+ import { agentStatusInfo } from "./workspace/list-host-agents.ts";
5
+ import type { AgentStatusInfo } from "./workspace/constants.ts";
6
+
7
+ /** Directory snapshots are authoritative; host UI cache absence is not a lifecycle event. */
8
+ export function useWorkspaceAgentStatuses(workspaceId: string) {
9
+ const paseo = usePaseo();
10
+ const [state, setState] = useState<{
11
+ paseo: typeof paseo;
12
+ workspaceId: string;
13
+ data: Record<string, AgentStatusInfo>;
14
+ }>();
15
+ useEffect(() => watchAgentDirectory(paseo.agents, (snapshot) => {
16
+ const data: Record<string, AgentStatusInfo> = {};
17
+ for (const agent of snapshot.values()) {
18
+ if (agent.workspaceId === workspaceId) data[agent.id] = agentStatusInfo(agent);
19
+ }
20
+ setState({ paseo, workspaceId, data });
21
+ }), [paseo, workspaceId]);
22
+ return { data: state?.paseo === paseo && state.workspaceId === workspaceId ? state.data : undefined };
23
+ }
@@ -16,6 +16,8 @@ export type AgentRowStyles = {
16
16
  agentListRow: ViewStyle;
17
17
  agentIconWrap: ViewStyle;
18
18
  runningBadge: ViewStyle;
19
+ subAgentBadge: ViewStyle;
20
+ subAgentBadgeText: TextStyle;
19
21
  listMain: ViewStyle;
20
22
  listLink: TextStyle;
21
23
  listTitle: TextStyle;
@@ -33,6 +35,7 @@ export function AgentRow({
33
35
  permissionCount,
34
36
  attentionKind,
35
37
  running,
38
+ subAgentCount = 0,
36
39
  busy,
37
40
  actionDisabled,
38
41
  theme,
@@ -47,12 +50,15 @@ export function AgentRow({
47
50
  permissionCount: number;
48
51
  attentionKind: AgentAttentionKind;
49
52
  running: boolean;
53
+ /** Direct child sessions; corner badge yields to running spinner. */
54
+ subAgentCount?: number;
50
55
  busy: boolean;
51
56
  actionDisabled: boolean;
52
57
  theme: WorkspaceTheme;
53
58
  styles: AgentRowStyles;
54
59
  onOpen: () => void;
55
- onArchiveToggle: () => void;
60
+ /** Omit to hide the archive control (attention popover). */
61
+ onArchiveToggle?: () => void;
56
62
  }): ReactNode {
57
63
  const [hovered, setHovered] = useState(false);
58
64
  // Web: hover-reveal. Native has no hover — keep the action visible.
@@ -76,6 +82,9 @@ export function AgentRow({
76
82
  : theme.colors.foregroundMuted;
77
83
  const stateLabels: string[] = [];
78
84
  if (!archived && running) stateLabels.push("running");
85
+ if (subAgentCount > 0) {
86
+ stateLabels.push(subAgentCount === 1 ? "1 subagent" : `${subAgentCount} subagents`);
87
+ }
79
88
  if (permissionCount > 0) {
80
89
  stateLabels.push(
81
90
  permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`,
@@ -84,6 +93,9 @@ export function AgentRow({
84
93
  if (!archived && attentionKind === "error") stateLabels.push("failed");
85
94
  if (!archived && attentionKind === "finished") stateLabels.push("turn finished, unread");
86
95
  const stateSuffix = stateLabels.length > 0 ? `, ${stateLabels.join(", ")}` : "";
96
+ const showRunning = running && !archived;
97
+ const showSubAgentCount = !showRunning && subAgentCount > 0;
98
+ const subAgentLabel = subAgentCount > 99 ? "99+" : String(subAgentCount);
87
99
 
88
100
  const body = (
89
101
  <>
@@ -93,10 +105,19 @@ export function AgentRow({
93
105
  size={18}
94
106
  color={botColor}
95
107
  />
96
- {running && !archived ? (
108
+ {showRunning ? (
97
109
  <View style={styles.runningBadge}>
98
110
  <RunningIndicator theme={theme} />
99
111
  </View>
112
+ ) : showSubAgentCount ? (
113
+ <View
114
+ accessibilityLabel={
115
+ subAgentCount === 1 ? "1 subagent" : `${subAgentCount} subagents`
116
+ }
117
+ style={styles.subAgentBadge}
118
+ >
119
+ <Text style={styles.subAgentBadgeText}>{subAgentLabel}</Text>
120
+ </View>
100
121
  ) : null}
101
122
  </View>
102
123
  <View style={styles.listMain}>
@@ -122,26 +143,32 @@ export function AgentRow({
122
143
  ) : null}
123
144
  </View>
124
145
  ) : null}
125
- <Pressable
126
- accessibilityRole="button"
127
- accessibilityLabel={archived ? `Unarchive ${label}` : `Archive ${label}`}
128
- accessibilityState={{ disabled: actionDisabled }}
129
- disabled={actionDisabled || !showAction}
130
- hitSlop={8}
131
- onPress={onArchiveToggle}
132
- pointerEvents={showAction ? "auto" : "none"}
133
- style={[styles.titleAction, { opacity: showAction ? 1 : 0 }]}
134
- >
135
- {busy ? (
136
- <ActivityIndicator size="small" color={theme.colors.foregroundMuted} />
137
- ) : (
138
- <Icon
139
- name={archived ? "ArchiveRestore" : "Archive"}
140
- size={14}
141
- color={theme.colors.foregroundMuted}
142
- />
143
- )}
144
- </Pressable>
146
+ {onArchiveToggle ? (
147
+ <Pressable
148
+ accessibilityRole="button"
149
+ accessibilityLabel={archived ? `Unarchive ${label}` : `Archive ${label}`}
150
+ accessibilityState={{ disabled: actionDisabled }}
151
+ disabled={actionDisabled || !showAction}
152
+ hitSlop={8}
153
+ onPress={onArchiveToggle}
154
+ pointerEvents={showAction ? "auto" : "none"}
155
+ style={[styles.titleAction, { opacity: showAction ? 1 : 0 }]}
156
+ >
157
+ {busy ? (
158
+ <ActivityIndicator
159
+ size={14}
160
+ color={theme.colors.foregroundMuted}
161
+ style={{ width: 14, height: 14 }}
162
+ />
163
+ ) : (
164
+ <Icon
165
+ name={archived ? "ArchiveRestore" : "Archive"}
166
+ size={14}
167
+ color={theme.colors.foregroundMuted}
168
+ />
169
+ )}
170
+ </Pressable>
171
+ ) : null}
145
172
  </>
146
173
  );
147
174
 
@@ -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. */
@@ -13,12 +13,16 @@ export type AgentLifecycleFilter = "idle" | "running" | "error" | "closed";
13
13
  export type MenuFlyout = "sort" | "group" | "show" | "status" | "lifecycle";
14
14
 
15
15
  export type AgentStatusInfo = {
16
+ /** Explicit host archive state; absent means unknown. */
17
+ archivedAt?: string | null;
16
18
  rank: number;
17
19
  updatedAt: string | null;
18
20
  status: string | null;
19
21
  permissionCount: number;
20
22
  requiresAttention: boolean;
21
23
  attentionReason: string | null;
24
+ /** Host parent session; null for top-level agents. */
25
+ parentAgentId: string | null;
22
26
  };
23
27
 
24
28
  /** Icon highlight for attention states; permission keeps the 033 warning badge. */
@@ -39,6 +43,39 @@ export function isAgentRunning(info: AgentStatusInfo | undefined): boolean {
39
43
  return info?.status === "running";
40
44
  }
41
45
 
46
+ /** Direct children only (`parentAgentId === agentId`); host status map is the source. */
47
+ export function countDirectSubAgents(
48
+ agentId: string,
49
+ byId: Record<string, AgentStatusInfo> | undefined,
50
+ ): number {
51
+ if (!byId) return 0;
52
+ let count = 0;
53
+ for (const info of Object.values(byId)) {
54
+ if (info.parentAgentId === agentId) count += 1;
55
+ }
56
+ return count;
57
+ }
58
+
59
+ /** parentId → direct child count from usage.agents, scoped by Status filter (041). */
60
+ export function countSubAgentsByParent(
61
+ items: ReadonlyArray<{ parentAgentId?: string | null; archivedAt?: string | null }>,
62
+ statusFilters: ReadonlySet<AgentStatusFilter>,
63
+ ): Record<string, number> {
64
+ const includeActive = statusFilters.has("active");
65
+ const includeArchived = statusFilters.has("archived");
66
+ if (!includeActive && !includeArchived) return {};
67
+
68
+ const counts: Record<string, number> = {};
69
+ for (const item of items) {
70
+ const archived = item.archivedAt != null;
71
+ if (archived ? !includeArchived : !includeActive) continue;
72
+ const parentId = item.parentAgentId?.trim();
73
+ if (!parentId) continue;
74
+ counts[parentId] = (counts[parentId] ?? 0) + 1;
75
+ }
76
+ return counts;
77
+ }
78
+
42
79
  export type MenuOption = { id: string; label: string; icon: string };
43
80
 
44
81
  /** Agents header row / search pill height — keep fixed to avoid layout jump. */
@@ -77,6 +114,7 @@ export const SHOW_FIELD_OPTIONS: ReadonlyArray<MenuOption & { id: AgentShowField
77
114
  { id: "calls", label: "Calls", icon: "Terminal" },
78
115
  { id: "messages", label: "Messages", icon: "MessageSquare" },
79
116
  { id: "updated", label: "Updated", icon: "Clock" },
117
+ { id: "prompt", label: "Prompt", icon: "Quote" },
80
118
  ];
81
119
 
82
120
  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
  }
@@ -0,0 +1,46 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import type { AgentUsageItem } from "../../shared/usage.ts";
4
+ import { reconcileHostArchive } from "./host-archive-sync.ts";
5
+ import { agentStatusInfo } from "./list-host-agents.ts";
6
+
7
+ function item(agentId: string, archivedAt: string | null = null): AgentUsageItem {
8
+ return {
9
+ agentId,
10
+ provider: "cursor",
11
+ title: agentId,
12
+ callCount: 0,
13
+ skillCalls: 0,
14
+ mcpCalls: 0,
15
+ shellCalls: 0,
16
+ fileReads: 0,
17
+ fileWrites: 0,
18
+ messageCount: 0,
19
+ coding: false,
20
+ createdAt: "2026-09-20T00:00:00.000Z",
21
+ updatedAt: "2026-09-20T00:00:00.000Z",
22
+ archivedAt,
23
+ parentAgentId: null,
24
+ lastActivityAt: null,
25
+ };
26
+ }
27
+
28
+ test("missing host cache and closed status do not synthesize archive", () => {
29
+ const rows = [item("a")];
30
+ assert.equal(reconcileHostArchive(rows, undefined)[0], rows[0]);
31
+ assert.equal(reconcileHostArchive(rows, {})[0], rows[0]);
32
+ const statuses = { a: agentStatusInfo({ id: "a", status: "closed", archivedAt: null }) };
33
+ assert.equal(reconcileHostArchive(rows, statuses)[0]?.archivedAt, null);
34
+ });
35
+
36
+ test("explicit host archive and unarchive override delayed DB results without changing metrics", () => {
37
+ const row = { ...item("a"), callCount: 42 };
38
+ const archived = { a: agentStatusInfo({ id: "a", archivedAt: "2026-09-20T08:30:43.446Z" }) };
39
+ const first = reconcileHostArchive([row], archived)[0]!;
40
+ assert.equal(first.archivedAt, archived.a.archivedAt);
41
+ assert.equal(first.callCount, 42);
42
+ assert.equal(row.archivedAt, null);
43
+ assert.equal(reconcileHostArchive([row], archived)[0]?.archivedAt, first.archivedAt);
44
+ const active = { a: agentStatusInfo({ id: "a", archivedAt: null }) };
45
+ assert.equal(reconcileHostArchive([first], active)[0]?.archivedAt, null);
46
+ });
@@ -0,0 +1,15 @@
1
+ import type { AgentUsageItem } from "../../shared/usage.ts";
2
+ import type { AgentStatusInfo } from "./constants.ts";
3
+
4
+ /** Preserve DB metrics while explicit host archive state wins over delayed RPC results. */
5
+ export function reconcileHostArchive(
6
+ items: ReadonlyArray<AgentUsageItem>,
7
+ statuses: Record<string, AgentStatusInfo> | undefined,
8
+ ): AgentUsageItem[] {
9
+ return items.map((item) => {
10
+ const archivedAt = statuses?.[item.agentId]?.archivedAt;
11
+ return archivedAt === undefined || archivedAt === item.archivedAt
12
+ ? item
13
+ : { ...item, archivedAt };
14
+ });
15
+ }