Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import { ThreadDetailsControl } from "./ThreadDetailsControl";
3import { ThreadHoverCardPopup } from "../ThreadHoverCard";
4import { ThreadDetailsSection } from "./ThreadDetailsSection";
5import { CollapsibleSectionHeader, SectionHeaderStatus } from "../ui/collapsible-section-header";
6import { SubagentTooltipContent } from "./SubagentTooltipContent";
7import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
8import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
9import {
10 deriveWorkflowGroups,
11 projectedSubagentsToRuntime,
12 type RuntimeSubagent,
13} from "@t3tools/client-runtime/state/subagentRuntime";
14import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
15import {
16 deriveThreadRelationshipGraph,
17 immediateThreadRelationships,
18 isParentThreadRelationship,
19 threadRelationshipRowStatus,
20 orderWebThreadLineageRows,
21 resolveMergeBackTargetThreadId,
22 type ThreadRelationshipEdge,
23 type ThreadRelationshipWalkRow,
24} from "@t3tools/client-runtime/state/thread-relationships";
25import {
26 canDetachThreadProviderSession,
27 resolveLatestMergeBackRun,
28} from "@t3tools/client-runtime/state/thread-workflows";
29import {
30 NodeId,
31 type EnvironmentId,
32 type OrchestrationV2Subagent,
33 type OrchestrationV2ThreadShell,
34 type ThreadId,
35} from "@t3tools/contracts";
36import { deriveSubagentElapsedMs } from "@t3tools/shared/orchestrationTiming";
37import { groupBy } from "effect/Array";
38import * as DateTime from "effect/DateTime";
39import { useNavigate } from "@tanstack/react-router";
40import {
41 ArrowRightIcon,
42 BotIcon,
43 CornerLeftUpIcon,
44 GitForkIcon,
45 LoaderCircleIcon,
46 MoreHorizontalIcon,
47 PlusIcon,
48 SquareIcon,
49 UnplugIcon,
50} from "lucide-react";
51import { useMemo, useState, type ReactNode } from "react";
52
53import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
54import { buildThreadRouteParams } from "../../threadRoutes";
55import {
56 useProjects,
57 useServerConfigs,
58 useThreadProjection,
59 useThreadShells,
60} from "../../state/entities";
61import { threadEnvironment } from "../../state/threads";
62import { orchestrationEnvironment } from "../../state/orchestration";
63import { useAtomCommand } from "../../state/use-atom-command";
64import { AgentElapsed } from "./AgentElapsed";
65import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
66import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";
67
68import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
69import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
70import { toastManager } from "../ui/toast";
71import {
72 THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
73 THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
74 THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
75} from "./threadDetailsPanelStyles";
76
77const THREAD_LINEAGE_INITIAL_COUNT = 6;
78const THREAD_LINEAGE_PAGE_COUNT = 12;
79
80export function resolveThreadLineageWindow<Row>(
81 rows: ReadonlyArray<Row>,
82 visibleCount: number,
83): { readonly visibleRows: ReadonlyArray<Row>; readonly hiddenCount: number } {
84 const visibleRows = rows.slice(0, visibleCount);
85 return { visibleRows, hiddenCount: rows.length - visibleRows.length };
86}
87
88export function ThreadLineageRowList(props: {
89 readonly hiddenCount: number;
90 readonly onShowMore: () => void;
91 readonly children: ReactNode;
92}) {
93 return (
94 <>
95 {/*
96 Plain overflow, not a ScrollArea
97 component: this sits inside an already scrolling panel, where a
98 max-height-only virtual viewport measures badly.
99 */}
100 <ul
101 aria-label="Related threads"
102 className="m-0 max-h-[13.5rem] list-none overflow-y-auto overscroll-contain p-0 has-data-workflow-expanded:max-h-[min(28rem,55dvh)]"
103 >
104 {props.children}
105 </ul>
106 {props.hiddenCount > 0 ? (
107 <button
108 type="button"
109 onClick={props.onShowMore}
110 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]`}
111 >
112 <PlusIcon aria-hidden className="size-4 shrink-0" />
113 Show {Math.min(props.hiddenCount, THREAD_LINEAGE_PAGE_COUNT)} more
114 </button>
115 ) : null}
116 </>
117 );
118}
119
120function ThreadLineageGroup(props: {
121 readonly label: string | null;
122 readonly rows: ReadonlyArray<ThreadRelationshipWalkRow>;
123 readonly expanded: boolean;
124 readonly children: (rows: ReadonlyArray<ThreadRelationshipWalkRow>) => ReactNode;
125}) {
126 const [expanded, setExpanded] = useState(props.expanded);
127 const [visibleCount, setVisibleCount] = useState(THREAD_LINEAGE_INITIAL_COUNT);
128 const { visibleRows, hiddenCount } = resolveThreadLineageWindow(props.rows, visibleCount);
129 const failedCount = props.rows.filter(
130 ({ edge }) => edge.status === "failed" || edge.status === "error",
131 ).length;
132 if (props.rows.length === 0) return null;
133 return (
134 <div>
135 {props.label ? (
136 <CollapsibleSectionHeader
137 variant="panel"
138 expanded={expanded}
139 onClick={() => setExpanded(!expanded)}
140 accessory={
141 failedCount > 0 ? <SectionHeaderStatus>{failedCount} failed</SectionHeaderStatus> : null
142 }
143 >
144 {props.label}
145 {!expanded && ` (${props.rows.length})`}
146 </CollapsibleSectionHeader>
147 ) : null}
148 {expanded ? (
149 <ThreadLineageRowList
150 hiddenCount={hiddenCount}
151 onShowMore={() => setVisibleCount((count) => count + THREAD_LINEAGE_PAGE_COUNT)}
152 >
153 {props.children(visibleRows)}
154 </ThreadLineageRowList>
155 ) : null}
156 </div>
157 );
158}
159
160function relationshipLabel(edge: ThreadRelationshipEdge, currentThreadId: ThreadId) {
161 if (edge.kind === "transfer") return "Context transfer";
162 if (edge.kind === "subagent") {
163 return edge.sourceThreadId === currentThreadId ? "Subagent" : "Parent agent";
164 }
165 return edge.sourceThreadId === currentThreadId ? "Fork" : "Parent thread";
166}
167
168function relationshipThreadTitle(input: {
169 readonly title: string;
170 readonly isSubagent: boolean;
171}): string {
172 if (!input.isSubagent) return input.title;
173 return formatSubagentDisplayTitle(input.title);
174}
175
176function currentSubagent<Agent extends RuntimeSubagent>(
177 agent: Agent | undefined,
178 childThread: OrchestrationV2ThreadShell | null | undefined,
179): Agent | undefined {
180 const liveStatus =
181 childThread?.activityRunStatus ?? (childThread?.status === "queued" ? "queued" : null);
182 if (!agent || !childThread) return agent;
183 const newerRun =
184 childThread.latestRunRequestedAt &&
185 DateTime.toEpochMillis(childThread.latestRunRequestedAt) >
186 Date.parse(agent.completedAt ?? agent.startedAt ?? agent.updatedAt);
187 if (!liveStatus && !newerRun) return agent;
188 const status = liveStatus ?? childThread.status;
189 const startedAt = liveStatus ? childThread.activityRunStartedAt : childThread.latestRunStartedAt;
190 const completedAt = liveStatus ? null : childThread.latestRunCompletedAt;
191 return {
192 ...agent,
193 status:
194 status === "preparing" || status === "starting" || status === "queued"
195 ? "pending"
196 : status === "rolled_back"
197 ? "interrupted"
198 : status,
199 startedAt: startedAt ? DateTime.formatIso(startedAt) : null,
200 completedAt: completedAt ? DateTime.formatIso(completedAt) : null,
201 progress: null,
202 result: null,
203 error: null,
204 };
205}
206
207export function ThreadRelationshipsPanel(props: {
208 readonly environmentId: EnvironmentId;
209 readonly threadId: ThreadId;
210}) {
211 const ref = scopeThreadRef(props.environmentId, props.threadId);
212 const projection = useThreadProjection(ref)?.projection ?? null;
213 const providers = useServerConfigs().get(props.environmentId)?.providers;
214 const runtimeSubagents = useMemo(
215 () => projectedSubagentsToRuntime(projection?.subagents ?? []),
216 [projection?.subagents],
217 );
218 const subagentsByThreadId = useMemo(() => {
219 const byId = new Map(runtimeSubagents.map((agent) => [agent.id, agent]));
220 return new Map(
221 (projection?.subagents ?? [])
222 .filter((subagent) => subagent.childThreadId !== null)
223 .map((subagent) => [
224 subagent.childThreadId,
225 {
226 ...byId.get(subagent.id)!,
227 id: subagent.id,
228 threadId: subagent.threadId,
229 runId: subagent.runId,
230 nativeTaskRef: subagent.nativeTaskRef,
231 nativeStatus: subagent.status,
232 driver: subagent.driver,
233 providerInstanceId: subagent.providerInstanceId,
234 origin: subagent.origin,
235 modelSelection: subagent.modelSelection,
236 },
237 ]),
238 );
239 }, [projection?.subagents, runtimeSubagents]);
240 const workflowGroupsById = useMemo(
241 () =>
242 new Map(deriveWorkflowGroups(runtimeSubagents).map((group) => [group.workflow.id, group])),
243 [runtimeSubagents],
244 );
245 const threadShells = useThreadShells();
246 const projects = useProjects().filter((project) => project.environmentId === props.environmentId);
247 const archived = useArchivedThreadSnapshots([props.environmentId]);
248 const archivedShells = archived.snapshots.find(
249 (entry) => entry.environmentId === props.environmentId,
250 )?.snapshot.threads;
251 const graph = useMemo(() => {
252 const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
253 ...threadShells
254 .filter((thread) => thread.environmentId === props.environmentId)
255 .map((thread) => thread.source),
256 ...(archivedShells ?? []),
257 ];
258 return deriveThreadRelationshipGraph({ threads: shells, projection });
259 }, [archivedShells, projection, props.environmentId, threadShells]);
260 const currentThread = projection?.thread ?? graph.nodes.get(props.threadId)?.thread;
261 const currentProject = projects.find((project) => project.id === currentThread?.projectId);
262 const navigate = useNavigate();
263 const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
264 const stopSession = useAtomCommand(threadEnvironment.stopSession);
265 const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
266 const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
267 const canOperateWorkflow = useAtomValue(
268 orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
269 );
270 const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
271 const [stoppingId, setStoppingId] = useState<string | null>(null);
272 const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
273 const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
274 const relationshipRows = useMemo(
275 () =>
276 orderWebThreadLineageRows({
277 graph,
278 rows: immediateThreadRelationships(graph, props.threadId),
279 currentThreadId: props.threadId,
280 mergeTargetThreadId,
281 }).map((row) => {
282 const agent =
283 row.edge.kind === "subagent" && !isParentThreadRelationship(row.edge, props.threadId)
284 ? subagentsByThreadId.get(row.threadId)
285 : undefined;
286 const workflowGroup = agent === undefined ? undefined : workflowGroupsById.get(agent.id);
287 return workflowGroup === undefined
288 ? row
289 : { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
290 }),
291 [graph, mergeTargetThreadId, props.threadId, subagentsByThreadId, workflowGroupsById],
292 );
293 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
294 const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
295
296 const {
297 related = [],
298 active = [],
299 previous = [],
300 } = groupBy(relationshipRows, ({ edge }) => {
301 if (edge.kind !== "subagent" || isParentThreadRelationship(edge, props.threadId))
302 return "related";
303 return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
304 edge.status ?? "",
305 )
306 ? "previous"
307 : "active";
308 });
309 const groups = [
310 { id: "related", label: null, rows: related, expanded: true },
311 { id: "active", label: null, rows: active, expanded: true },
312 { id: "previous", label: "Previous agents", rows: previous, expanded: false },
313 ];
314 const runningCount =
315 (projection?.subagents.filter(
316 (agent) => agent.childThreadId === null && agent.status === "running",
317 ).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
318
319 if (relationshipRows.length === 0 && runningCount === 0) {
320 return null;
321 }
322
323 const openThread = (threadId: ThreadId) => {
324 void navigate({
325 to: "/$environmentId/$threadId",
326 params: buildThreadRouteParams(scopeThreadRef(props.environmentId, threadId)),
327 });
328 };
329
330 const merge = async () => {
331 if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
332 setBusyAction("merge");
333 const result = await mergeBack({
334 environmentId: props.environmentId,
335 input: {
336 sourceThreadId: props.threadId,
337 targetThreadId: mergeTargetThreadId,
338 runId: latestMergeBackRun.id,
339 },
340 });
341 setBusyAction(null);
342 if (result._tag === "Success") openThread(mergeTargetThreadId);
343 };
344
345 const detach = async () => {
346 if (!canDetach || busyAction !== null) return;
347 setBusyAction("detach");
348 await stopSession({
349 environmentId: props.environmentId,
350 input: { threadId: props.threadId },
351 });
352 setBusyAction(null);
353 };
354
355 const stopSubagent = async (
356 childThreadId: ThreadId,
357 agent: Pick<OrchestrationV2Subagent, "id" | "origin" | "threadId">,
358 ) => {
359 if (stoppingId !== null) return;
360 setStoppingId(childThreadId);
361 const result = await interruptTurn({
362 environmentId: props.environmentId,
363 input:
364 agent.origin === "provider_native"
365 ? { threadId: agent.threadId, subagentId: agent.id }
366 : { threadId: childThreadId },
367 });
368 setStoppingId(null);
369 if (result._tag === "Failure") {
370 toastManager.add({ type: "error", title: "Could not stop subagent" });
371 }
372 };
373
374 const stopWorkflow = async (subagentId: string) => {
375 if (stoppingId !== null) return;
376 setStoppingId(subagentId);
377 const result = await stopWorkflowCommand({
378 environmentId: props.environmentId,
379 input: { threadId: props.threadId, subagentId: NodeId.make(subagentId) },
380 });
381 setStoppingId(null);
382 if (result._tag === "Failure") {
383 toastManager.add({ type: "error", title: "Could not stop workflow" });
384 }
385 };
386
387 const parentTitle =
388 mergeTargetThreadId === null
389 ? null
390 : (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
391
392 return (
393 <ThreadDetailsSection
394 headingId="thread-details-lineage-heading"
395 title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
396 data-thread-relationships-panel
397 actions={
398 canDetach ? (
399 <Menu>
400 <MenuTrigger
401 render={
402 <ThreadDetailsControl
403 size="icon-xs"
404 variant="ghost"
405 part="icon"
406 aria-label="More thread actions"
407 disabled={busyAction !== null}
408 />
409 }
410 >
411 <MoreHorizontalIcon className="size-3.5" />
412 </MenuTrigger>
413 <MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
414 <MenuItem onClick={() => void detach()}>
415 <UnplugIcon className="size-3.5" />
416 Disconnect agent session
417 </MenuItem>
418 </MenuPopup>
419 </Menu>
420 ) : null
421 }
422 >
423 {groups.map((group) => (
424 <ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
425 {(visibleRows) =>
426 visibleRows.map(({ threadId, edge }) => {
427 const node = graph.nodes.get(threadId);
428 const isSubagent = edge.kind === "subagent";
429 const isMergeTarget = threadId === mergeTargetThreadId;
430 const isParent = isParentThreadRelationship(edge, props.threadId);
431 const rowStatus = threadRelationshipRowStatus(graph, { threadId, edge });
432 const RelationshipIcon = isParent
433 ? CornerLeftUpIcon
434 : isSubagent
435 ? BotIcon
436 : GitForkIcon;
437 const relationship = relationshipLabel(edge, props.threadId);
438 const projectedAgent =
439 isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
440 const workflowGroup =
441 projectedAgent === undefined
442 ? undefined
443 : workflowGroupsById.get(projectedAgent.id);
444 const agent = workflowGroup
445 ? projectedAgent
446 : currentSubagent(projectedAgent, node?.thread);
447 const failed = rowStatus === "failed" || rowStatus === "error";
448 const canStop =
449 agent &&
450 (agent.origin === "app_owned" ||
451 (agent.origin === "provider_native" &&
452 agent.driver === "claudeAgent" &&
453 agent.runId != null &&
454 agent.nativeTaskRef?.strength === "strong" &&
455 agent.nativeTaskRef.nativeId !== null &&
456 ["pending", "running", "waiting"].includes(agent.nativeStatus))) &&
457 agent.startedAt &&
458 ["pending", "running", "waiting"].includes(agent.status);
459 const threadTitle = relationshipThreadTitle({
460 title:
461 workflowGroup?.workflow.workflowName ??
462 node?.thread?.title ??
463 agent?.title ??
464 threadId,
465 isSubagent,
466 });
467 const provider = providers?.find(
468 (entry) =>
469 entry.instanceId ===
470 (agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
471 );
472 const providerDriver = agent?.driver ?? provider?.driver;
473 const canStopWorkflow =
474 canOperateWorkflow &&
475 workflowGroup?.workflow.status === "running" &&
476 agent?.origin === "provider_native" &&
477 providerDriver === "claudeAgent";
478 const trailingVisibilityClass = (workflowGroup ? canStopWorkflow : canStop)
479 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
480 : "";
481 const project = projects.find((project) => project.id === node?.thread?.projectId);
482 const relationshipHint = node?.missing
483 ? "This related thread is unavailable"
484 : `Open ${relationship.toLowerCase()} in this chat`;
485 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
486 const relationshipTooltip = agent ? (
487 <SubagentTooltipContent
488 title={threadTitle}
489 model={agent.model}
490 providerInstanceId={agent.providerInstanceId}
491 origin={agent.origin}
492 modelSelection={agent.modelSelection}
493 provider={provider}
494 providers={providers}
495 driver={providerDriver}
496 elapsed={<AgentElapsed agent={agent} />}
497 status={agent.status}
498 result={agent.result}
499 progress={agent.progress}
500 parentThread={currentThread ?? undefined}
501 childThread={node?.thread ?? undefined}
502 parentProject={currentProject}
503 childProject={project}
504 />
505 ) : (
506 relationshipHint
507 );
508 const relationshipContent = (
509 <>
510 <ThreadRelationshipIcon
511 driver={isSubagent && !isParent ? providerDriver : undefined}
512 provider={provider}
513 fallbackIcon={RelationshipIcon}
514 status={rowStatus}
515 />
516 <span className="min-w-0 flex-1">
517 <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
518 {threadTitle}
519 </span>
520 </span>
521 {agent ? null : (
522 <ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
523 )}
524 {agent &&
525 !failed &&
526 (deriveSubagentElapsedMs(agent, 0) !== null || canStopWorkflow) ? (
527 <span
528 className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${canStopWorkflow ? "min-w-6 text-end" : ""} ${trailingVisibilityClass}`}
529 >
530 <AgentElapsed agent={agent} compact />
531 </span>
532 ) : !isMergeTarget ? (
533 <span
534 className={
535 workflowGroup
536 ? "sr-only"
537 : `shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`
538 }
539 >
540 {threadRelationshipStatusLabel(rowStatus)}
541 </span>
542 ) : null}
543 </>
544 );
545 const relationshipLink = (
546 <Tooltip>
547 <TooltipTrigger
548 delay={200}
549 render={
550 <ThreadDetailsControl
551 size="sm"
552 variant="ghost"
553 part={workflowGroup ? "primary" : "row"}
554 disabled={node?.missing === true}
555 onClick={() => openThread(threadId)}
556 />
557 }
558 >
559 {relationshipContent}
560 </TooltipTrigger>
561 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
562 </Tooltip>
563 );
564 if (workflowGroup && agent) {
565 return (
566 <ThreadLineageWorkflowRow
567 key={threadId}
568 group={workflowGroup}
569 providerInstanceId={agent.providerInstanceId}
570 provider={provider}
571 providers={providers}
572 driver={providerDriver}
573 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
574 isThreadAvailable={(memberThreadId) =>
575 graph.nodes.get(memberThreadId as ThreadId)?.missing === false
576 }
577 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
578 stopping={stoppingId === agent.id}
579 stopDisabled={stoppingId !== null}
580 header={relationshipLink}
581 />
582 );
583 }
584 return (
585 <li key={threadId} className="group relative flex h-8 items-center rounded-lg">
586 {isMergeTarget ? (
587 <div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
588 <Tooltip>
589 <TooltipTrigger
590 delay={200}
591 render={
592 <ThreadDetailsControl
593 size="sm"
594 variant="ghost"
595 part="primary"
596 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
597 disabled={node?.missing === true}
598 onClick={() => openThread(threadId)}
599 />
600 }
601 >
602 {relationshipContent}
603 </TooltipTrigger>
604 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
605 </Tooltip>
606 <span
607 aria-hidden="true"
608 className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
609 />
610 <Tooltip>
611 <TooltipTrigger
612 render={
613 <ThreadDetailsControl
614 size="sm"
615 variant="ghost"
616 part="secondary"
617 aria-label={
618 parentTitle
619 ? `Merge back to ${parentTitle}`
620 : "Merge back to source conversation"
621 }
622 disabled={!canMerge || busyAction !== null}
623 onClick={() => void merge()}
624 >
625 {busyAction === "merge" ? (
626 <LoaderCircleIcon className="size-3 animate-spin" />
627 ) : (
628 <PullRequestGlyph.merged className="size-3" />
629 )}
630 </ThreadDetailsControl>
631 }
632 />
633 <TooltipPopup side="left">
634 {latestMergeBackRun === null
635 ? "Complete a run in this fork before merging it back"
636 : parentTitle
637 ? `Merge this conversation back into ${parentTitle}`
638 : "Merge this conversation back into its source"}
639 </TooltipPopup>
640 </Tooltip>
641 <span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
642 {threadRelationshipStatusLabel(rowStatus)}
643 </span>
644 </div>
645 ) : (
646 relationshipLink
647 )}
648 {canStop && agent ? (
649 <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">
650 <Tooltip>
651 <TooltipTrigger
652 render={
653 <ThreadDetailsControl
654 size="icon-xs"
655 variant="ghost"
656 part="icon"
657 tone="destructive"
658 aria-label={`Stop subagent ${threadTitle}`}
659 disabled={stoppingId !== null}
660 onClick={() => void stopSubagent(threadId, agent)}
661 />
662 }
663 >
664 {stoppingId === threadId ? (
665 <LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
666 ) : (
667 <SquareIcon aria-hidden className="size-3 fill-current" />
668 )}
669 </TooltipTrigger>
670 <TooltipPopup side="left">Stop subagent</TooltipPopup>
671 </Tooltip>
672 </div>
673 ) : null}
674 </li>
675 );
676 })
677 }
678 </ThreadLineageGroup>
679 ))}
680 </ThreadDetailsSection>
681 );
682}