@koinzhang/paseo-plugin-activity 0.2.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.
- package/CHANGELOG.md +50 -1
- package/README.md +26 -11
- package/client/attention-agents.test.ts +94 -0
- package/client/attention-agents.ts +67 -0
- package/client/attention-pill.tsx +254 -0
- package/client/attention-popover.tsx +161 -0
- package/client/attention-status-store.ts +47 -0
- package/client/formatted-time.tsx +23 -0
- package/client/global-surface.tsx +3 -1
- package/client/hidden-pill-recheck.test.ts +33 -0
- package/client/hidden-pill-recheck.ts +22 -0
- package/client/latest-user-message.test.ts +34 -0
- package/client/latest-user-message.ts +96 -0
- package/client/open-agent.ts +32 -0
- package/client/panel.tsx +117 -107
- package/client/pill-directory.test.ts +92 -0
- package/client/pill-directory.ts +79 -0
- package/client/pill.tsx +23 -23
- package/client/usage-popover.tsx +75 -84
- package/client/usage-query.tsx +8 -3
- package/client/usage-stats.tsx +2 -2
- package/client/use-agent-turn-end.ts +72 -0
- package/client/use-latest-user-message.ts +15 -0
- package/client/use-workspace-agent-statuses.ts +47 -0
- package/client/workspace/agent-live-status-sync.tsx +103 -0
- package/client/workspace/agent-row.tsx +105 -28
- package/client/workspace/agents-section.tsx +92 -17
- package/client/workspace/constants.test.ts +66 -0
- package/client/workspace/constants.ts +66 -4
- package/client/workspace/filters.test.ts +59 -0
- package/client/workspace/filters.ts +11 -2
- package/client/workspace/list-host-agents.test.ts +103 -0
- package/client/workspace/list-host-agents.ts +113 -23
- package/client/workspace/panel.tsx +192 -12
- package/client/workspace/rank-section.tsx +36 -26
- package/client/workspace/running-indicator.tsx +54 -0
- package/client/workspace/status-cache.test.ts +62 -0
- package/client/workspace/status-cache.ts +23 -0
- package/client/workspace/terminal-preview.test.ts +17 -0
- package/client/workspace/terminal-preview.ts +10 -0
- package/client/workspace/terminals-section.tsx +155 -0
- package/index.client.tsx +7 -1
- package/index.server.ts +2 -0
- package/package.json +3 -3
- package/server/agents.test.ts +16 -0
- package/server/agents.ts +7 -4
- package/server/handlers-query.test.ts +24 -3
- package/server/handlers.ts +17 -5
- package/server/skill-path.ts +3 -20
- package/shared/explorer-agent-display.ts +1 -1
- package/shared/format.test.ts +35 -31
- package/shared/format.ts +21 -36
- package/shared/home-path.ts +19 -0
- package/shared/usage.test.ts +8 -2
- package/shared/usage.ts +16 -0
|
@@ -9,15 +9,22 @@ 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;
|
|
19
|
+
subAgentBadge: ViewStyle;
|
|
20
|
+
subAgentBadgeText: TextStyle;
|
|
16
21
|
listMain: ViewStyle;
|
|
17
22
|
listLink: TextStyle;
|
|
18
23
|
listTitle: TextStyle;
|
|
19
24
|
listMeta: TextStyle;
|
|
20
25
|
titleAction: ViewStyle;
|
|
26
|
+
permissionBadge: ViewStyle;
|
|
27
|
+
permissionBadgeText: TextStyle;
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
export function AgentRow({
|
|
@@ -25,6 +32,10 @@ export function AgentRow({
|
|
|
25
32
|
archived,
|
|
26
33
|
canOpen,
|
|
27
34
|
meta,
|
|
35
|
+
permissionCount,
|
|
36
|
+
attentionKind,
|
|
37
|
+
running,
|
|
38
|
+
subAgentCount = 0,
|
|
28
39
|
busy,
|
|
29
40
|
actionDisabled,
|
|
30
41
|
theme,
|
|
@@ -36,12 +47,18 @@ export function AgentRow({
|
|
|
36
47
|
archived: boolean;
|
|
37
48
|
canOpen: boolean;
|
|
38
49
|
meta: string | null;
|
|
50
|
+
permissionCount: number;
|
|
51
|
+
attentionKind: AgentAttentionKind;
|
|
52
|
+
running: boolean;
|
|
53
|
+
/** Direct child sessions; corner badge yields to running spinner. */
|
|
54
|
+
subAgentCount?: number;
|
|
39
55
|
busy: boolean;
|
|
40
56
|
actionDisabled: boolean;
|
|
41
57
|
theme: WorkspaceTheme;
|
|
42
58
|
styles: AgentRowStyles;
|
|
43
59
|
onOpen: () => void;
|
|
44
|
-
|
|
60
|
+
/** Omit to hide the archive control (attention popover). */
|
|
61
|
+
onArchiveToggle?: () => void;
|
|
45
62
|
}): ReactNode {
|
|
46
63
|
const [hovered, setHovered] = useState(false);
|
|
47
64
|
// Web: hover-reveal. Native has no hover — keep the action visible.
|
|
@@ -55,13 +72,54 @@ export function AgentRow({
|
|
|
55
72
|
} as object)
|
|
56
73
|
: null;
|
|
57
74
|
|
|
75
|
+
const botColor =
|
|
76
|
+
!archived && attentionKind === "error"
|
|
77
|
+
? theme.colors.statusDanger
|
|
78
|
+
: !archived && attentionKind === "permission"
|
|
79
|
+
? theme.colors.statusWarning
|
|
80
|
+
: !archived && attentionKind === "finished"
|
|
81
|
+
? theme.colors.statusSuccess
|
|
82
|
+
: theme.colors.foregroundMuted;
|
|
83
|
+
const stateLabels: string[] = [];
|
|
84
|
+
if (!archived && running) stateLabels.push("running");
|
|
85
|
+
if (subAgentCount > 0) {
|
|
86
|
+
stateLabels.push(subAgentCount === 1 ? "1 subagent" : `${subAgentCount} subagents`);
|
|
87
|
+
}
|
|
88
|
+
if (permissionCount > 0) {
|
|
89
|
+
stateLabels.push(
|
|
90
|
+
permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (!archived && attentionKind === "error") stateLabels.push("failed");
|
|
94
|
+
if (!archived && attentionKind === "finished") stateLabels.push("turn finished, unread");
|
|
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);
|
|
99
|
+
|
|
58
100
|
const body = (
|
|
59
101
|
<>
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
102
|
+
<View style={styles.agentIconWrap}>
|
|
103
|
+
<Icon
|
|
104
|
+
name={archived ? "BotOff" : "Bot"}
|
|
105
|
+
size={18}
|
|
106
|
+
color={botColor}
|
|
107
|
+
/>
|
|
108
|
+
{showRunning ? (
|
|
109
|
+
<View style={styles.runningBadge}>
|
|
110
|
+
<RunningIndicator theme={theme} />
|
|
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>
|
|
121
|
+
) : null}
|
|
122
|
+
</View>
|
|
65
123
|
<View style={styles.listMain}>
|
|
66
124
|
<Text style={canOpen ? styles.listLink : styles.listTitle} numberOfLines={1}>
|
|
67
125
|
{label}
|
|
@@ -72,26 +130,45 @@ export function AgentRow({
|
|
|
72
130
|
</Text>
|
|
73
131
|
) : null}
|
|
74
132
|
</View>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
133
|
+
{permissionCount > 0 ? (
|
|
134
|
+
<View
|
|
135
|
+
accessibilityLabel={
|
|
136
|
+
permissionCount === 1 ? "1 pending permission" : `${permissionCount} pending permissions`
|
|
137
|
+
}
|
|
138
|
+
style={styles.permissionBadge}
|
|
139
|
+
>
|
|
140
|
+
<Icon name="ShieldAlert" size={12} color={theme.colors.statusWarning} />
|
|
141
|
+
{permissionCount > 1 ? (
|
|
142
|
+
<Text style={styles.permissionBadgeText}>{permissionCount}</Text>
|
|
143
|
+
) : null}
|
|
144
|
+
</View>
|
|
145
|
+
) : null}
|
|
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}
|
|
95
172
|
</>
|
|
96
173
|
);
|
|
97
174
|
|
|
@@ -99,7 +176,7 @@ export function AgentRow({
|
|
|
99
176
|
return (
|
|
100
177
|
<Pressable
|
|
101
178
|
accessibilityRole="link"
|
|
102
|
-
accessibilityLabel={`Open conversation ${label}`}
|
|
179
|
+
accessibilityLabel={`Open conversation ${label}${stateSuffix}`}
|
|
103
180
|
onPress={onOpen}
|
|
104
181
|
style={styles.agentListRow}
|
|
105
182
|
{...hoverProps}
|
|
@@ -10,13 +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,
|
|
17
|
+
attentionKind,
|
|
18
|
+
countSubAgentsByParent,
|
|
19
|
+
isAgentRunning,
|
|
16
20
|
SEARCH_ANIM_MS,
|
|
17
21
|
SEARCH_TITLE_GAP,
|
|
18
22
|
type AgentGroup,
|
|
19
23
|
type AgentShowField,
|
|
24
|
+
type AgentStatusFilter,
|
|
20
25
|
type AgentStatusInfo,
|
|
21
26
|
} from "./constants.ts";
|
|
22
27
|
import { formatAgentMeta } from "./filters.ts";
|
|
@@ -42,6 +47,72 @@ export type AgentsSectionStyles = AgentRowStyles & {
|
|
|
42
47
|
pagerLabel: TextStyle;
|
|
43
48
|
};
|
|
44
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
|
+
|
|
45
116
|
export function AgentsSection({
|
|
46
117
|
theme,
|
|
47
118
|
styles,
|
|
@@ -49,7 +120,9 @@ export function AgentsSection({
|
|
|
49
120
|
agentGroup,
|
|
50
121
|
agentShowFields,
|
|
51
122
|
statuses,
|
|
123
|
+
agentItems,
|
|
52
124
|
visibleAgentItems,
|
|
125
|
+
statusFilters,
|
|
53
126
|
statusFiltersEmpty,
|
|
54
127
|
busyAgentId,
|
|
55
128
|
openAgent,
|
|
@@ -68,8 +141,12 @@ export function AgentsSection({
|
|
|
68
141
|
agentGroup: AgentGroup;
|
|
69
142
|
agentShowFields: ReadonlySet<AgentShowField>;
|
|
70
143
|
statuses: Record<string, AgentStatusInfo> | undefined;
|
|
144
|
+
/** Full workspace registry list (unfiltered) — source for subagent counts (041). */
|
|
145
|
+
agentItems: ReadonlyArray<AgentUsageItem>;
|
|
71
146
|
/** Already filtered / sorted / search-matched. */
|
|
72
147
|
visibleAgentItems: ReadonlyArray<AgentUsageItem>;
|
|
148
|
+
/** Status menu Active / Archived — scopes subagent badge counts. */
|
|
149
|
+
statusFilters: ReadonlySet<AgentStatusFilter>;
|
|
73
150
|
statusFiltersEmpty: boolean;
|
|
74
151
|
busyAgentId: string | null;
|
|
75
152
|
openAgent?: (opts: { agentId: string }) => void;
|
|
@@ -163,28 +240,26 @@ export function AgentsSection({
|
|
|
163
240
|
);
|
|
164
241
|
}, [agentGroup, pageItems]);
|
|
165
242
|
|
|
243
|
+
const subAgentCounts = useMemo(
|
|
244
|
+
() => countSubAgentsByParent(agentItems, statusFilters),
|
|
245
|
+
[agentItems, statusFilters],
|
|
246
|
+
);
|
|
247
|
+
|
|
166
248
|
function renderAgentRow(item: AgentUsageItem): ReactNode {
|
|
167
|
-
const label = item.title ?? item.agentId;
|
|
168
|
-
const archived = item.archivedAt != null;
|
|
169
|
-
const canOpen = openAgent != null && !archived;
|
|
170
|
-
const meta = formatAgentMeta(item, agentShowFields, statuses, locale);
|
|
171
|
-
const busy = busyAgentId === item.agentId;
|
|
172
249
|
return (
|
|
173
|
-
<
|
|
250
|
+
<WorkspaceAgentRow
|
|
174
251
|
key={item.agentId}
|
|
175
|
-
|
|
176
|
-
archived={archived}
|
|
177
|
-
canOpen={canOpen}
|
|
178
|
-
meta={meta}
|
|
179
|
-
busy={busy}
|
|
180
|
-
actionDisabled={busy || busyAgentId != null}
|
|
252
|
+
item={item}
|
|
181
253
|
theme={theme}
|
|
182
254
|
styles={styles}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
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}
|
|
188
263
|
/>
|
|
189
264
|
);
|
|
190
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. */
|
|
@@ -16,8 +16,64 @@ 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;
|
|
22
|
+
/** Host parent session; null for top-level agents. */
|
|
23
|
+
parentAgentId: string | null;
|
|
19
24
|
};
|
|
20
25
|
|
|
26
|
+
/** Icon highlight for attention states; permission keeps the 033 warning badge. */
|
|
27
|
+
export type AgentAttentionKind = "finished" | "permission" | "error" | null;
|
|
28
|
+
|
|
29
|
+
export function attentionKind(info: AgentStatusInfo | undefined): AgentAttentionKind {
|
|
30
|
+
if (!info) return null;
|
|
31
|
+
if (info.status === "error") return "error";
|
|
32
|
+
if (info.permissionCount > 0) return "permission";
|
|
33
|
+
if (!info.requiresAttention) return null;
|
|
34
|
+
if (info.attentionReason === "error") return "error";
|
|
35
|
+
if (info.attentionReason === "finished") return "finished";
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Host lifecycle says the agent is actively working a turn (spinner badge). */
|
|
40
|
+
export function isAgentRunning(info: AgentStatusInfo | undefined): boolean {
|
|
41
|
+
return info?.status === "running";
|
|
42
|
+
}
|
|
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
|
+
|
|
21
77
|
export type MenuOption = { id: string; label: string; icon: string };
|
|
22
78
|
|
|
23
79
|
/** Agents header row / search pill height — keep fixed to avoid layout jump. */
|
|
@@ -29,10 +85,13 @@ export const MENU_SUBMENU_OVERLAP = 5;
|
|
|
29
85
|
export const MENU_WIDTH = 232;
|
|
30
86
|
export const MENU_OPTION_ICON_SIZE = 14;
|
|
31
87
|
/** Approx list-row height (padding + title/meta) for stable Skills/MCP section size. */
|
|
32
|
-
export const RANK_ROW_ESTIMATE =
|
|
88
|
+
export const RANK_ROW_ESTIMATE = 42;
|
|
33
89
|
/** Visible agents per page in Explorer; pager hidden when pageCount ≤ 1. */
|
|
34
90
|
export const AGENT_PAGE_SIZE = 40;
|
|
35
91
|
export const HOST_AGENT_PAGE_LIMIT = 200;
|
|
92
|
+
/** Open terminals poll cadence; the capture preview polls at the same rate while expanded. */
|
|
93
|
+
export const TERMINAL_REFETCH_MS = 5_000;
|
|
94
|
+
export const TERMINAL_PREVIEW_LINES = 8;
|
|
36
95
|
|
|
37
96
|
export const SORT_OPTIONS: ReadonlyArray<MenuOption & { id: AgentSort }> = [
|
|
38
97
|
{ id: "updated", label: "Updated", icon: "Clock" },
|
|
@@ -53,6 +112,7 @@ export const SHOW_FIELD_OPTIONS: ReadonlyArray<MenuOption & { id: AgentShowField
|
|
|
53
112
|
{ id: "calls", label: "Calls", icon: "Terminal" },
|
|
54
113
|
{ id: "messages", label: "Messages", icon: "MessageSquare" },
|
|
55
114
|
{ id: "updated", label: "Updated", icon: "Clock" },
|
|
115
|
+
{ id: "prompt", label: "Prompt", icon: "Quote" },
|
|
56
116
|
];
|
|
57
117
|
|
|
58
118
|
export const STATUS_FILTER_OPTIONS: ReadonlyArray<MenuOption & { id: AgentStatusFilter }> = [
|
|
@@ -81,12 +141,14 @@ export function attentionRank(agent: {
|
|
|
81
141
|
status?: string;
|
|
82
142
|
requiresAttention?: boolean;
|
|
83
143
|
attentionReason?: string | null;
|
|
144
|
+
pendingPermissions?: ReadonlyArray<unknown>;
|
|
84
145
|
}): number {
|
|
85
146
|
if (
|
|
86
147
|
agent.requiresAttention === true ||
|
|
87
148
|
agent.attentionReason === "permission" ||
|
|
88
149
|
agent.attentionReason === "error" ||
|
|
89
|
-
agent.status === "error"
|
|
150
|
+
agent.status === "error" ||
|
|
151
|
+
(agent.pendingPermissions?.length ?? 0) > 0
|
|
90
152
|
) {
|
|
91
153
|
return 0;
|
|
92
154
|
}
|
|
@@ -117,5 +179,5 @@ export function agentUpdatedAt(
|
|
|
117
179
|
item: AgentUsageItem,
|
|
118
180
|
byId: Record<string, AgentStatusInfo> | undefined,
|
|
119
181
|
): string | null {
|
|
120
|
-
return
|
|
182
|
+
return byId?.[item.agentId]?.updatedAt ?? item.updatedAt ?? item.lastActivityAt ?? null;
|
|
121
183
|
}
|
|
@@ -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
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { matchesAgentTitleSearch } from "../../shared/agent-title-search.ts";
|
|
2
|
-
import {
|
|
2
|
+
import { formatActivityTime } from "../../shared/format.ts";
|
|
3
3
|
import { providerLabel, type AgentUsageItem } from "../../shared/usage.ts";
|
|
4
4
|
import {
|
|
5
5
|
type AgentShowField,
|
|
@@ -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));
|
|
@@ -23,7 +28,11 @@ export function formatAgentMeta(
|
|
|
23
28
|
if (showFields.has("messages")) parts.push(`${item.messageCount} messages`);
|
|
24
29
|
if (showFields.has("updated")) {
|
|
25
30
|
const at = agentUpdatedAt(item, byId);
|
|
26
|
-
if (at) parts.push(
|
|
31
|
+
if (at) parts.push(formatActivityTime(at, locale));
|
|
32
|
+
}
|
|
33
|
+
if (showFields.has("prompt")) {
|
|
34
|
+
const preview = promptPreview?.trim();
|
|
35
|
+
if (preview) parts.push(preview);
|
|
27
36
|
}
|
|
28
37
|
if (parts.length === 0) return null;
|
|
29
38
|
return parts.join(" · ");
|