Skip to content

Commit aad564b

Browse files
thomaspblockcursoragentwesbillman
authored
Move agent activity below composer (#579)
Co-authored-by: Cursor <[email protected]> Co-authored-by: Wes <[email protected]>
1 parent bda98da commit aad564b

17 files changed

Lines changed: 641 additions & 189 deletions

‎desktop/src/features/agents/observerRelayStore.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ export function getAgentTranscript(
269269
return state?.items ?? EMPTY_TRANSCRIPT;
270270
}
271271

272-
export function useManagedAgentObserverBridge(agents: readonly ManagedAgent[]) {
272+
export function useManagedAgentObserverBridge(
273+
agents: readonly Pick<ManagedAgent, "pubkey" | "status">[],
274+
) {
273275
const hasActiveAgent = React.useMemo(
274276
() =>
275277
agents.some(

‎desktop/src/features/agents/ui/ManagedAgentSessionPanel.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
XCircle,
99
} from "lucide-react";
1010

11+
import { isManagedAgentActive } from "@/features/agents/lib/managedAgentControlActions";
1112
import type { ManagedAgent } from "@/shared/api/types";
1213
import { cn } from "@/shared/lib/cn";
1314
import { Badge } from "@/shared/ui/badge";
@@ -23,7 +24,7 @@ import { shorten } from "./agentSessionUtils";
2324
import { useObserverEvents, useAgentTranscript } from "./useObserverEvents";
2425

2526
type ManagedAgentSessionPanelProps = {
26-
agent: ManagedAgent;
27+
agent: Pick<ManagedAgent, "pubkey" | "name" | "status">;
2728
channelId?: string | null;
2829
className?: string;
2930
emptyDescription?: string;
@@ -39,12 +40,12 @@ export function ManagedAgentSessionPanel({
3940
showHeader = true,
4041
showRaw = true,
4142
}: ManagedAgentSessionPanelProps) {
42-
const isRunning = agent.status === "running";
43+
const hasObserver = isManagedAgentActive(agent);
4344
const { connectionState, errorMessage, events } = useObserverEvents(
44-
isRunning,
45+
hasObserver,
4546
agent.pubkey,
4647
);
47-
const transcript = useAgentTranscript(isRunning, agent.pubkey);
48+
const transcript = useAgentTranscript(hasObserver, agent.pubkey);
4849

4950
// Filter transcript items by channelId (lightweight — items now carry channelId)
5051
const scopedTranscript = React.useMemo(
@@ -83,7 +84,7 @@ export function ManagedAgentSessionPanel({
8384
<SessionHeader
8485
connectionState={connectionState}
8586
eventCount={scopedEvents.length}
86-
hasObserver={isRunning}
87+
hasObserver={hasObserver}
8788
latestSessionId={latestSessionId}
8889
/>
8990
) : null}
@@ -94,7 +95,7 @@ export function ManagedAgentSessionPanel({
9495
emptyDescription={emptyDescription}
9596
errorMessage={errorMessage}
9697
events={scopedEvents}
97-
hasObserver={isRunning}
98+
hasObserver={hasObserver}
9899
showRaw={showRaw}
99100
transcript={scopedTranscript}
100101
/>

‎desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { Activity, Bot, CircleDot, Octagon, X } from "lucide-react";
33
import { toast } from "sonner";
44

55
import { ManagedAgentSessionPanel } from "@/features/agents/ui/ManagedAgentSessionPanel";
6+
import { isManagedAgentActive } from "@/features/agents/lib/managedAgentControlActions";
67
import { cancelManagedAgentTurn } from "@/shared/api/agentControl";
7-
import type { Channel, ManagedAgent } from "@/shared/api/types";
8+
import type { Channel } from "@/shared/api/types";
89
import { useEscapeKey } from "@/shared/hooks/useEscapeKey";
910
import { useIsThreadPanelOverlay } from "@/shared/hooks/use-mobile";
1011
import { useStickToBottom } from "@/shared/hooks/useStickToBottom";
@@ -17,11 +18,13 @@ import {
1718
PANEL_OVERLAY_CLASS,
1819
} from "@/shared/ui/OverlayPanelBackdrop";
1920
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
21+
import type { ChannelAgentSessionAgent } from "./useChannelAgentSessions";
2022

2123
type AgentSessionThreadPanelProps = {
22-
agent: ManagedAgent;
24+
agent: ChannelAgentSessionAgent;
2325
canResetWidth: boolean;
2426
channel: Channel;
27+
canInterruptTurn: boolean;
2528
isWorking: boolean;
2629
onClose: () => void;
2730
onResetWidth: () => void;
@@ -32,14 +35,15 @@ type AgentSessionThreadPanelProps = {
3235
export function AgentSessionThreadPanel({
3336
agent,
3437
canResetWidth,
38+
canInterruptTurn,
3539
channel,
3640
isWorking,
3741
onClose,
3842
onResetWidth,
3943
onResizeStart,
4044
widthPx,
4145
}: AgentSessionThreadPanelProps) {
42-
const isLive = agent.status === "running";
46+
const isLive = isManagedAgentActive(agent);
4347
const isOverlay = useIsThreadPanelOverlay();
4448
useEscapeKey(onClose, isOverlay);
4549

@@ -118,7 +122,7 @@ export function AgentSessionThreadPanel({
118122
<Button
119123
aria-label="Stop current agent turn"
120124
data-testid="agent-session-stop-turn"
121-
disabled={!isLive || !isWorking}
125+
disabled={!canInterruptTurn || !isLive || !isWorking}
122126
onClick={() => {
123127
void handleInterruptTurn();
124128
}}
@@ -132,7 +136,9 @@ export function AgentSessionThreadPanel({
132136
</TooltipTrigger>
133137
<TooltipContent side="bottom" className="text-xs">
134138
{isWorking
135-
? "Interrupt the current ACP turn without stopping the agent process."
139+
? canInterruptTurn
140+
? "Interrupt the current ACP turn without stopping the agent process."
141+
: "This agent cannot be interrupted from this workspace."
136142
: "No active turn to interrupt."}
137143
</TooltipContent>
138144
</Tooltip>

‎desktop/src/features/channels/ui/BotActivityBar.tsx‎

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as React from "react";
22
import { Loader2 } from "lucide-react";
33

4+
import { useAgentTranscript } from "@/features/agents/ui/useObserverEvents";
5+
import type { TranscriptItem } from "@/features/agents/ui/agentSessionTypes";
6+
import { formatToolTitle } from "@/features/agents/ui/agentSessionToolCatalog";
47
import type { UserProfileLookup } from "@/features/profile/lib/identity";
58
import type { ManagedAgent } from "@/shared/api/types";
69
import { cn } from "@/shared/lib/cn";
@@ -11,21 +14,38 @@ export type BotActivityAgent = Pick<ManagedAgent, "pubkey" | "name">;
1114

1215
type BotActivityBarProps = {
1316
agents: BotActivityAgent[];
17+
channelId?: string | null;
1418
onOpenAgentSession: (pubkey: string) => void;
1519
openAgentSessionPubkey: string | null;
1620
profiles?: UserProfileLookup;
1721
typingBotPubkeys: string[];
22+
variant?: "toolbar" | "inline";
1823
};
1924

2025
const HOVER_OPEN_DELAY_MS = 150;
2126
const HOVER_CLOSE_DELAY_MS = 180;
27+
const HEADLINE_ROTATION_MS = 2200;
28+
29+
function getActivityHeadline(item: TranscriptItem): string | null {
30+
if (item.type === "tool") {
31+
return formatToolTitle(item.sproutToolName ?? item.toolName, item.title);
32+
}
33+
34+
if (item.type === "message") {
35+
return item.role === "assistant" ? "Responding" : item.title;
36+
}
37+
38+
return item.title;
39+
}
2240

2341
export function BotActivityComposerAction({
2442
agents,
43+
channelId = null,
2544
onOpenAgentSession,
2645
openAgentSessionPubkey,
2746
profiles,
2847
typingBotPubkeys,
48+
variant = "toolbar",
2949
}: BotActivityBarProps) {
3050
const [open, setOpen] = React.useState(false);
3151
const hoverTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(
@@ -39,6 +59,39 @@ export function BotActivityComposerAction({
3959

4060
return agents.filter((agent) => typingSet.has(agent.pubkey.toLowerCase()));
4161
}, [agents, typingBotPubkeys]);
62+
const singleTypingAgent =
63+
typingAgents.length === 1 ? (typingAgents[0] ?? null) : null;
64+
const transcript = useAgentTranscript(
65+
Boolean(singleTypingAgent),
66+
singleTypingAgent?.pubkey,
67+
);
68+
const activityHeadlines = React.useMemo(() => {
69+
if (!singleTypingAgent) {
70+
return [];
71+
}
72+
73+
const seen = new Set<string>();
74+
const headlines: string[] = [];
75+
const scopedTranscript = channelId
76+
? transcript.filter((item) => item.channelId === channelId)
77+
: transcript;
78+
79+
for (let i = scopedTranscript.length - 1; i >= 0; i--) {
80+
const headline = getActivityHeadline(scopedTranscript[i]);
81+
if (!headline || seen.has(headline)) {
82+
continue;
83+
}
84+
85+
seen.add(headline);
86+
headlines.unshift(headline);
87+
if (headlines.length >= 5) {
88+
break;
89+
}
90+
}
91+
92+
return headlines;
93+
}, [channelId, singleTypingAgent, transcript]);
94+
const [headlineIndex, setHeadlineIndex] = React.useState(0);
4295

4396
const clearHoverTimer = React.useCallback(() => {
4497
if (hoverTimerRef.current !== null) {
@@ -69,6 +122,18 @@ export function BotActivityComposerAction({
69122
return () => clearHoverTimer();
70123
}, [clearHoverTimer]);
71124

125+
React.useEffect(() => {
126+
if (activityHeadlines.length <= 1) {
127+
return;
128+
}
129+
130+
const interval = window.setInterval(() => {
131+
setHeadlineIndex((current) => (current + 1) % activityHeadlines.length);
132+
}, HEADLINE_ROTATION_MS);
133+
134+
return () => window.clearInterval(interval);
135+
}, [activityHeadlines.length]);
136+
72137
if (typingAgents.length === 0) {
73138
return null;
74139
}
@@ -80,13 +145,26 @@ export function BotActivityComposerAction({
80145
typingAgents.length === 1
81146
? `${typingAgents[0]?.name ?? "Agent"} is working`
82147
: `${typingAgents.length} agents working`;
148+
const isInline = variant === "inline";
149+
const visibleStatusLabel =
150+
typingAgents.length === 1
151+
? `${typingAgents[0]?.name ?? "Agent"}: ${
152+
activityHeadlines[headlineIndex % activityHeadlines.length] ??
153+
"Working"
154+
}`
155+
: `${typingAgents[0]?.name ?? "Agent"} +${typingAgents.length - 1}`;
83156

84157
return (
85158
<Popover onOpenChange={setOpen} open={open}>
86159
<PopoverTrigger asChild>
87160
<button
88161
aria-label={`${triggerLabel}. View activity.`}
89-
className="inline-flex h-9 min-w-9 items-center justify-center gap-1.5 rounded-full border border-border/60 bg-background px-2 text-xs font-medium text-muted-foreground transition-colors hover:border-primary/30 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring data-[state=open]:border-primary/40 data-[state=open]:bg-primary/10 data-[state=open]:text-primary"
162+
className={cn(
163+
"inline-flex items-center justify-center rounded-full border border-border/60 bg-background font-medium text-muted-foreground transition-colors hover:border-primary/30 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring data-[state=open]:border-primary/40 data-[state=open]:bg-primary/10 data-[state=open]:text-primary",
164+
isInline
165+
? "h-7 min-w-0 gap-2 border-transparent bg-transparent px-0 text-xs font-semibold leading-none shadow-none hover:border-transparent hover:bg-transparent data-[state=open]:border-transparent data-[state=open]:bg-transparent"
166+
: "h-9 min-w-9 gap-1.5 px-2 text-xs",
167+
)}
90168
data-testid="bot-activity-composer-trigger"
91169
onBlur={closeWithDelay}
92170
onClick={() => {
@@ -102,7 +180,12 @@ export function BotActivityComposerAction({
102180
{typingAgents.slice(0, 2).map((agent) => (
103181
<UserAvatar
104182
avatarUrl={agentAvatarUrl(agent)}
105-
className="!h-5 !w-5 rounded-full border border-background text-[8px]"
183+
className={cn(
184+
"rounded-full border border-background",
185+
isInline
186+
? "!h-[18px] !w-[18px] shadow-sm ring-1 ring-primary/25 text-[7px]"
187+
: "!h-5 !w-5 text-[8px]",
188+
)}
106189
displayName={agent.name}
107190
key={agent.pubkey}
108191
/>
@@ -113,11 +196,20 @@ export function BotActivityComposerAction({
113196
+{typingAgents.length - 2}
114197
</span>
115198
) : null}
116-
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin opacity-70" />
199+
<span
200+
className={cn(
201+
isInline ? "agent-activity-shimmer max-w-40 truncate" : "sr-only",
202+
)}
203+
>
204+
{isInline ? visibleStatusLabel : "working"}
205+
</span>
206+
{isInline ? null : (
207+
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin opacity-70" />
208+
)}
117209
</button>
118210
</PopoverTrigger>
119211
<PopoverContent
120-
align="end"
212+
align={isInline ? "start" : "end"}
121213
className="w-64 p-2"
122214
onMouseEnter={keepOpen}
123215
onMouseLeave={closeWithDelay}

0 commit comments

Comments
 (0)