Repository navigation
Expand file tree
/
Copy pathThreadRelationshipsControl.tsx
More file actions
697 lines (680 loc) · 29.3 KB
/
Copy pathThreadRelationshipsControl.tsx
File metadata and controls
697 lines (680 loc) · 29.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
import { ThreadDetailsControl } from "./ThreadDetailsControl";
import { ThreadHoverCardPopup } from "../ThreadHoverCard";
import { ThreadDetailsSection } from "./ThreadDetailsSection";
import { CollapsibleSectionHeader, SectionHeaderStatus } from "../ui/collapsible-section-header";
import { SubagentTooltipContent } from "./SubagentTooltipContent";
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
applyAgentListView,
isAgentListViewFiltered,
type AgentListSubject,
} from "@t3tools/client-runtime/state/agent-list-view";
import {
edgeAgentStatus,
liveSubagent,
subagentSpawnedAt,
} from "@t3tools/client-runtime/state/agent-fleet";
import {
formatSubagentTokenCount,
isActiveSubagentStatus,
projectedSubagentsToRuntime,
} from "@t3tools/client-runtime/state/subagentRuntime";
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
import {
deriveThreadRelationshipGraph,
immediateThreadRelationships,
isParentThreadRelationship,
threadRelationshipRowStatus,
orderWebThreadLineageRows,
resolveMergeBackTargetThreadId,
type ThreadRelationshipEdge,
type ThreadRelationshipWalkRow,
} from "@t3tools/client-runtime/state/thread-relationships";
import {
canDetachThreadProviderSession,
resolveLatestMergeBackRun,
} from "@t3tools/client-runtime/state/thread-workflows";
import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
import { deriveSubagentElapsedMs } from "@t3tools/shared/orchestrationTiming";
import { groupBy } from "effect/Array";
import { useNavigate } from "@tanstack/react-router";
import {
ArrowRightIcon,
BotIcon,
CornerLeftUpIcon,
GitForkIcon,
LoaderCircleIcon,
MoreHorizontalIcon,
PanelRightIcon,
PlusIcon,
SquareIcon,
UnplugIcon,
} from "lucide-react";
import { useMemo, useState, type MouseEvent, type ReactNode } from "react";
import { useAgentListViewStore } from "../../agentListViewStore";
import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
import { useRightPanelStore } from "../../rightPanelStore";
import { buildThreadRouteParams } from "../../threadRoutes";
import {
useProjects,
useServerConfigs,
useThreadProjection,
useThreadShells,
} from "../../state/entities";
import { threadEnvironment } from "../../state/threads";
import { useAtomCommand } from "../../state/use-atom-command";
import { AgentElapsed } from "./AgentElapsed";
import { SubagentActivityLine } from "./SubagentActivityLine";
import { AgentListToolbar } from "./AgentListToolbar";
import { useAgentContextMenu } from "./agentContextMenu";
import { useAgentHandles } from "./agentReferences";
import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
import { Button } from "../ui/button";
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { toastManager } from "../ui/toast";
import {
THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
} from "./threadDetailsPanelStyles";
// Lineage paging: a busy thread can accumulate dozens of forks and subagents,
// and the panel it lives in already scrolls. Show a workable window, keep the
// rest behind Show more, and bound what is shown so the sections below Lineage
// stay reachable.
const THREAD_LINEAGE_INITIAL_COUNT = 6;
const THREAD_LINEAGE_PAGE_COUNT = 12;
export function resolveThreadLineageWindow<Row>(
rows: ReadonlyArray<Row>,
visibleCount: number,
): { readonly visibleRows: ReadonlyArray<Row>; readonly hiddenCount: number } {
const visibleRows = rows.slice(0, visibleCount);
return { visibleRows, hiddenCount: rows.length - visibleRows.length };
}
export function ThreadLineageRowList(props: {
readonly hiddenCount: number;
readonly onShowMore: () => void;
readonly children: ReactNode;
}) {
return (
<>
{/*
Bounded rather than free-growing so Lineage cannot push the rest of the
thread details panel out of view. Plain overflow, not a ScrollArea
component: this sits inside an already scrolling panel, where a
max-height-only virtual viewport measures badly. Every row is a focusable
button, so keyboard users reach and scroll the region through the rows
themselves and the container needs no extra tab stop of its own.
*/}
<ul
aria-label="Related threads"
className="m-0 max-h-[13.5rem] list-none overflow-y-auto overscroll-contain p-0"
>
{props.children}
</ul>
{props.hiddenCount > 0 ? (
<button
type="button"
onClick={props.onShowMore}
className={`flex h-8 w-full cursor-pointer items-center rounded-lg ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-sm font-medium text-muted-foreground/70 hover:bg-black/[0.055] hover:text-foreground/80 dark:hover:bg-white/[0.075]`}
>
<PlusIcon aria-hidden className="size-4 shrink-0" />
Show {Math.min(props.hiddenCount, THREAD_LINEAGE_PAGE_COUNT)} more
</button>
) : null}
</>
);
}
function ThreadLineageGroup(props: {
readonly label: string | null;
readonly rows: ReadonlyArray<ThreadRelationshipWalkRow>;
readonly expanded: boolean;
/** Fork: a filtered agents list shows its matches instead of a collapsed header. */
readonly forceExpanded?: boolean;
readonly children: (rows: ReadonlyArray<ThreadRelationshipWalkRow>) => ReactNode;
}) {
const [userExpanded, setExpanded] = useState(props.expanded);
const expanded = userExpanded || props.forceExpanded === true;
const [visibleCount, setVisibleCount] = useState(THREAD_LINEAGE_INITIAL_COUNT);
const { visibleRows, hiddenCount } = resolveThreadLineageWindow(props.rows, visibleCount);
const failedCount = props.rows.filter(
({ edge }) => edge.status === "failed" || edge.status === "error",
).length;
if (props.rows.length === 0) return null;
return (
<div>
{props.label ? (
<CollapsibleSectionHeader
expanded={expanded}
onClick={() => setExpanded(!expanded)}
accessory={
failedCount > 0 ? <SectionHeaderStatus>{failedCount} failed</SectionHeaderStatus> : null
}
>
{props.label}
{!expanded && ` (${props.rows.length})`}
</CollapsibleSectionHeader>
) : null}
{expanded ? (
<ThreadLineageRowList
hiddenCount={hiddenCount}
onShowMore={() => setVisibleCount((count) => count + THREAD_LINEAGE_PAGE_COUNT)}
>
{props.children(visibleRows)}
</ThreadLineageRowList>
) : null}
</div>
);
}
function relationshipLabel(edge: ThreadRelationshipEdge, currentThreadId: ThreadId) {
if (edge.kind === "transfer") return "Context transfer";
if (edge.kind === "subagent") {
return edge.sourceThreadId === currentThreadId ? "Subagent" : "Parent agent";
}
return edge.sourceThreadId === currentThreadId ? "Fork" : "Parent thread";
}
function relationshipThreadTitle(input: {
readonly title: string;
readonly isSubagent: boolean;
}): string {
if (!input.isSubagent) return input.title;
return formatSubagentDisplayTitle(input.title);
}
export function ThreadRelationshipsPanel(props: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
}) {
const ref = scopeThreadRef(props.environmentId, props.threadId);
const projection = useThreadProjection(ref)?.projection ?? null;
const providers = useServerConfigs().get(props.environmentId)?.providers;
const subagentsByThreadId = useMemo(
() =>
new Map(
(projection?.subagents ?? [])
.filter((subagent) => subagent.childThreadId !== null)
.map((subagent) => [
subagent.childThreadId,
{
...projectedSubagentsToRuntime([subagent])[0]!,
driver: subagent.driver,
providerInstanceId: subagent.providerInstanceId,
origin: subagent.origin,
modelSelection: subagent.modelSelection,
},
]),
),
[projection?.subagents],
);
const threadShells = useThreadShells();
const projects = useProjects().filter((project) => project.environmentId === props.environmentId);
const archived = useArchivedThreadSnapshots([props.environmentId]);
const archivedShells = archived.snapshots.find(
(entry) => entry.environmentId === props.environmentId,
)?.snapshot.threads;
const graph = useMemo(() => {
const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
...threadShells
.filter((thread) => thread.environmentId === props.environmentId)
.map((thread) => thread.source),
...(archivedShells ?? []),
];
return deriveThreadRelationshipGraph({ threads: shells, projection });
}, [archivedShells, projection, props.environmentId, threadShells]);
const currentThread = projection?.thread ?? graph.nodes.get(props.threadId)?.thread;
const currentProject = projects.find((project) => project.id === currentThread?.projectId);
const navigate = useNavigate();
const openAgentMenu = useAgentContextMenu(ref);
const agentHandles = useAgentHandles(ref.environmentId, ref.threadId);
const agentListView = useAgentListViewStore((state) => state.view);
const setAgentListView = useAgentListViewStore((state) => state.setView);
const workspaceRoot = currentThread?.worktreePath ?? currentProject?.workspaceRoot ?? null;
const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
const stopSession = useAtomCommand(threadEnvironment.stopSession);
const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
const [stoppingThreadId, setStoppingThreadId] = useState<ThreadId | null>(null);
const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
const relationshipRows = useMemo(
() =>
orderWebThreadLineageRows({
graph,
rows: immediateThreadRelationships(graph, props.threadId),
currentThreadId: props.threadId,
mergeTargetThreadId,
}),
[graph, mergeTargetThreadId, props.threadId],
);
const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
const {
related = [],
active = [],
previous = [],
} = groupBy(relationshipRows, ({ edge }) => {
if (edge.kind !== "subagent" || isParentThreadRelationship(edge, props.threadId))
return "related";
return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
edge.status ?? "",
)
? "previous"
: "active";
});
// Fork: the agents list's search, status filter and sort, in spawn order by default.
const agentSubject = ({ threadId, edge }: ThreadRelationshipWalkRow): AgentListSubject => {
const node = graph.nodes.get(threadId);
const recorded = subagentsByThreadId.get(threadId);
const agent = liveSubagent(recorded, node?.thread);
return {
title: relationshipThreadTitle({
title: node?.thread?.title ?? agent?.title ?? threadId,
isSubagent: true,
}),
model: agent?.model ?? null,
status: agent?.status ?? edgeAgentStatus(edge.status),
usage: agent?.usage ?? null,
// The child thread's creation, which a follow-up run never moves (`subagentSpawnedAt`).
spawnedAt: node?.thread
? subagentSpawnedAt(null, node.thread)
: (recorded?.startedAt ?? null),
startedAt: agent?.startedAt ?? null,
completedAt: agent?.completedAt ?? null,
};
};
const agentRowCount = active.length + previous.length;
const agentListFiltered = isAgentListViewFiltered(agentListView);
const visibleActive = applyAgentListView(active, agentListView, agentSubject);
const visiblePrevious = applyAgentListView(previous, agentListView, agentSubject);
const showAgentToolbar = agentRowCount > 1 || agentListFiltered;
const groups = [
{ id: "related", label: null, rows: related, expanded: true },
{ id: "active", label: null, rows: visibleActive, expanded: true },
{
id: "previous",
label: "Previous agents",
rows: visiblePrevious,
expanded: false,
forceExpanded: agentListFiltered,
},
];
// Subagents without a child thread yet have no row, so count them separately.
const runningCount =
(projection?.subagents.filter(
(agent) => agent.childThreadId === null && agent.status === "running",
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
if (relationshipRows.length === 0 && runningCount === 0) {
return null;
}
const openThread = (threadId: ThreadId) => {
void navigate({
to: "/$environmentId/$threadId",
params: buildThreadRouteParams(scopeThreadRef(props.environmentId, threadId)),
});
};
const merge = async () => {
if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
setBusyAction("merge");
const result = await mergeBack({
environmentId: props.environmentId,
input: {
sourceThreadId: props.threadId,
targetThreadId: mergeTargetThreadId,
runId: latestMergeBackRun.id,
},
});
setBusyAction(null);
if (result._tag === "Success") openThread(mergeTargetThreadId);
};
const detach = async () => {
if (!canDetach || busyAction !== null) return;
setBusyAction("detach");
await stopSession({
environmentId: props.environmentId,
input: { threadId: props.threadId },
});
setBusyAction(null);
};
const stopSubagent = async (childThreadId: ThreadId) => {
if (stoppingThreadId !== null) return;
setStoppingThreadId(childThreadId);
const result = await interruptTurn({
environmentId: props.environmentId,
input: { threadId: childThreadId },
});
setStoppingThreadId(null);
if (result._tag === "Failure") {
toastManager.add({ type: "error", title: "Could not stop subagent" });
}
};
const parentTitle =
mergeTargetThreadId === null
? null
: (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
return (
<ThreadDetailsSection
headingId="thread-details-lineage-heading"
title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
data-thread-relationships-panel
actions={
agentRowCount > 0 || runningCount > 0 || canDetach ? (
<>
{agentRowCount > 0 || runningCount > 0 ? (
// Fork: the same agents, with hover previews and nested agents, in the right panel.
<Tooltip>
<TooltipTrigger
render={
<ThreadDetailsControl
size="icon-xs"
variant="ghost"
part="icon"
aria-label="Open in Agents panel"
onClick={() => useRightPanelStore.getState().open(ref, "agents")}
/>
}
>
<PanelRightIcon className="size-3.5" />
</TooltipTrigger>
<TooltipPopup side="left">Open in Agents panel</TooltipPopup>
</Tooltip>
) : null}
{canDetach ? (
<Menu>
<MenuTrigger
render={
<ThreadDetailsControl
size="icon-xs"
variant="ghost"
part="icon"
aria-label="More thread actions"
disabled={busyAction !== null}
/>
}
>
<MoreHorizontalIcon className="size-3.5" />
</MenuTrigger>
<MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
<MenuItem onClick={() => void detach()}>
<UnplugIcon className="size-3.5" />
Disconnect agent session
</MenuItem>
</MenuPopup>
</Menu>
) : null}
</>
) : null
}
>
{showAgentToolbar ? (
<AgentListToolbar view={agentListView} onChange={setAgentListView} />
) : null}
{showAgentToolbar &&
agentListFiltered &&
visibleActive.length === 0 &&
visiblePrevious.length === 0 ? (
<div className="flex items-center justify-between gap-2 px-2.5 py-1.5">
<span className="text-xs text-muted-foreground">No agents match these filters.</span>
<Button
size="xs"
variant="outline"
onClick={() => setAgentListView({ ...agentListView, statuses: [], query: "" })}
>
Clear filters
</Button>
</div>
) : null}
{groups.map((group) => (
<ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
{(visibleRows) =>
visibleRows.map(({ threadId, edge }) => {
const node = graph.nodes.get(threadId);
const isSubagent = edge.kind === "subagent";
const isMergeTarget = threadId === mergeTargetThreadId;
const isParent = isParentThreadRelationship(edge, props.threadId);
const status = threadRelationshipRowStatus(graph, { threadId, edge });
const RelationshipIcon = isParent
? CornerLeftUpIcon
: isSubagent
? BotIcon
: GitForkIcon;
const relationship = relationshipLabel(edge, props.threadId);
const agent = liveSubagent(
isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined,
node?.thread,
);
const failed = status === "failed" || status === "error";
const canStop =
agent?.origin === "app_owned" &&
agent.startedAt &&
["pending", "running", "waiting"].includes(agent.status);
const trailingVisibilityClass = canStop
? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
: "";
const threadTitle = relationshipThreadTitle({
title: node?.thread?.title ?? agent?.title ?? threadId,
isSubagent,
});
const provider = providers?.find(
(entry) =>
entry.instanceId ===
(agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
);
const providerDriver = agent?.driver ?? provider?.driver;
const project = projects.find((project) => project.id === node?.thread?.projectId);
const relationshipHint = node?.missing
? "This related thread is unavailable"
: `Open ${relationship.toLowerCase()} in this chat`;
const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
const relationshipTooltip = agent ? (
<SubagentTooltipContent
title={threadTitle}
model={agent.model}
providerInstanceId={agent.providerInstanceId}
origin={agent.origin}
modelSelection={agent.modelSelection}
provider={provider}
providers={providers}
driver={providerDriver}
elapsed={<AgentElapsed agent={agent} />}
status={agent.status}
result={agent.result}
progress={agent.progress}
usage={agent.usage}
handle={agentHandles.get(threadId)}
parentThread={currentThread ?? undefined}
childThread={node?.thread ?? undefined}
parentProject={currentProject}
childProject={project}
/>
) : (
relationshipHint
);
// Fork: working agents add their latest tool call, failed agents their error.
const agentLive = agent !== undefined && isActiveSubagentStatus(agent.status);
// One truncated line; the full error stays in the hover card and the agent tab.
const agentError =
agent?.status === "failed" && agent.error
? agent.error.length > 160
? `${agent.error.slice(0, 159)}…`
: agent.error
: null;
const secondLine = agentLive ? (
<SubagentActivityLine
childRef={scopeThreadRef(props.environmentId, threadId)}
status={agent.status}
progress={agent.progress}
workspaceRoot={workspaceRoot}
/>
) : agentError ? (
<span className="block truncate text-left font-mono text-2xs font-normal text-destructive-foreground">
{agentError}
</span>
) : null;
const onAgentContextMenu =
agent && !node?.missing
? (event: MouseEvent<HTMLElement>) =>
openAgentMenu(event, { childThreadId: threadId, title: threadTitle })
: undefined;
const relationshipContent = (
<>
<ThreadRelationshipIcon
driver={isSubagent && !isParent ? providerDriver : undefined}
provider={provider}
fallbackIcon={RelationshipIcon}
status={status}
/>
<span className="min-w-0 flex-1">
<span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
{threadTitle}
</span>
{secondLine}
</span>
{agent ? null : (
<ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
)}
{/* One trailing item keeps room for the title: the icon dot already
carries status, so an agent with a known time shows only that. */}
{agent && !failed && deriveSubagentElapsedMs(agent, 0) !== null ? (
<span
className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${trailingVisibilityClass}`}
>
{agent.usage
? `${formatSubagentTokenCount(agent.usage.totalTokens)} · `
: null}
<AgentElapsed agent={agent} compact />
</span>
) : !isMergeTarget ? (
<span
className={`shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`}
>
{agent?.usage
? `${formatSubagentTokenCount(agent.usage.totalTokens)} · `
: null}
{threadRelationshipStatusLabel(status)}
</span>
) : null}
</>
);
return (
<li
key={threadId}
className={`group relative flex ${secondLine ? "min-h-8" : "h-8"} items-center rounded-lg`}
>
{isMergeTarget ? (
<div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
<Tooltip>
<TooltipTrigger
delay={200}
render={
<ThreadDetailsControl
size="sm"
variant="ghost"
part="primary"
aria-label={`${threadTitle} ${agent?.usage ? `${formatSubagentTokenCount(agent.usage.totalTokens)} · ` : ""}${threadRelationshipStatusLabel(status)}`}
disabled={node?.missing === true}
onClick={() => openThread(threadId)}
/>
}
>
{relationshipContent}
</TooltipTrigger>
<RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
</Tooltip>
<span
aria-hidden="true"
className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
/>
<Tooltip>
<TooltipTrigger
render={
<ThreadDetailsControl
size="sm"
variant="ghost"
part="secondary"
aria-label={
parentTitle
? `Merge back to ${parentTitle}`
: "Merge back to source conversation"
}
disabled={!canMerge || busyAction !== null}
onClick={() => void merge()}
>
{busyAction === "merge" ? (
<LoaderCircleIcon className="size-3 animate-spin" />
) : (
<PullRequestGlyph.merged className="size-3" />
)}
</ThreadDetailsControl>
}
/>
<TooltipPopup side="left">
{latestMergeBackRun === null
? "Complete a run in this fork before merging it back"
: parentTitle
? `Merge this conversation back into ${parentTitle}`
: "Merge this conversation back into its source"}
</TooltipPopup>
</Tooltip>
<span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
{agent?.usage
? `${formatSubagentTokenCount(agent.usage.totalTokens)} · `
: null}
{threadRelationshipStatusLabel(status)}
</span>
</div>
) : (
<Tooltip>
<TooltipTrigger
delay={200}
render={
<ThreadDetailsControl
size="sm"
variant="ghost"
disabled={node?.missing === true}
onClick={() => openThread(threadId)}
onContextMenu={onAgentContextMenu}
multiline={secondLine !== null}
part="row"
/>
}
>
{relationshipContent}
</TooltipTrigger>
<RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
</Tooltip>
)}
{canStop && agent ? (
<div className="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 pointer-coarse:pointer-events-auto pointer-coarse:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100">
<Tooltip>
<TooltipTrigger
render={
<ThreadDetailsControl
size="icon-xs"
variant="ghost"
part="icon"
tone="destructive"
aria-label={`Stop subagent ${threadTitle}`}
disabled={stoppingThreadId !== null}
onClick={() => void stopSubagent(threadId)}
/>
}
>
{stoppingThreadId === threadId ? (
<LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
) : (
<SquareIcon aria-hidden className="size-3 fill-current" />
)}
</TooltipTrigger>
<TooltipPopup side="left">Stop subagent</TooltipPopup>
</Tooltip>
</div>
) : null}
</li>
);
})
}
</ThreadLineageGroup>
))}
</ThreadDetailsSection>
);
}