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 { 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 serverConfigs = useServerConfigs();
214 const threadShells = useThreadShells();
215 const allProjects = useProjects();
216 const archived = useArchivedThreadSnapshots([props.environmentId]);
217 const navigate = useNavigate();
218 const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
219 const stopSession = useAtomCommand(threadEnvironment.stopSession);
220 const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
221 const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
222 const canOperateWorkflow = useAtomValue(
223 orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
224 );
225 const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
226 const [stoppingId, setStoppingId] = useState<string | null>(null);
227 // These lookups and the graph walk every subagent and thread, so they sit below
228 // the panel's hooks where the compiler can cache them.
229 const providers = serverConfigs.get(props.environmentId)?.providers;
230 const projects = allProjects.filter((project) => project.environmentId === props.environmentId);
231 const archivedShells = archived.snapshots.find(
232 (entry) => entry.environmentId === props.environmentId,
233 )?.snapshot.threads;
234 const projected = projection?.subagents ?? [];
235 const runtimeSubagents = projectedSubagentsToRuntime(projected);
236 const byId = new Map(runtimeSubagents.map((agent) => [agent.id, agent]));
237 const subagentsByThreadId = new Map(
238 projected
239 .filter((subagent) => subagent.childThreadId !== null)
240 .map((subagent) => [
241 subagent.childThreadId,
242 {
243 ...byId.get(subagent.id)!,
244 id: subagent.id,
245 threadId: subagent.threadId,
246 runId: subagent.runId,
247 nativeTaskRef: subagent.nativeTaskRef,
248 nativeStatus: subagent.status,
249 driver: subagent.driver,
250 providerInstanceId: subagent.providerInstanceId,
251 origin: subagent.origin,
252 modelSelection: subagent.modelSelection,
253 },
254 ]),
255 );
256 const workflowGroupsById = new Map(
257 deriveWorkflowGroups(runtimeSubagents).map((group) => [group.workflow.id, group]),
258 );
259 const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
260 ...threadShells
261 .filter((thread) => thread.environmentId === props.environmentId)
262 .map((thread) => thread.source),
263 ...(archivedShells ?? []),
264 ];
265 const graph = deriveThreadRelationshipGraph({ threads: shells, projection });
266 const currentThread = projection?.thread ?? graph.nodes.get(props.threadId)?.thread;
267 const currentProject = projects.find((project) => project.id === currentThread?.projectId);
268 const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
269 const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
270 const relationshipRows = orderWebThreadLineageRows({
271 graph,
272 rows: immediateThreadRelationships(graph, props.threadId),
273 currentThreadId: props.threadId,
274 mergeTargetThreadId,
275 }).map((row) => {
276 const agent =
277 row.edge.kind === "subagent" && !isParentThreadRelationship(row.edge, props.threadId)
278 ? subagentsByThreadId.get(row.threadId)
279 : undefined;
280 const workflowGroup = agent === undefined ? undefined : workflowGroupsById.get(agent.id);
281 return workflowGroup === undefined
282 ? row
283 : { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
284 });
285 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
286 const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
287
288 const {
289 related = [],
290 active = [],
291 previous = [],
292 } = groupBy(relationshipRows, ({ edge }) => {
293 if (edge.kind !== "subagent" || isParentThreadRelationship(edge, props.threadId))
294 return "related";
295 return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
296 edge.status ?? "",
297 )
298 ? "previous"
299 : "active";
300 });
301 const groups = [
302 { id: "related", label: null, rows: related, expanded: true },
303 { id: "active", label: null, rows: active, expanded: true },
304 { id: "previous", label: "Previous agents", rows: previous, expanded: false },
305 ];
306 const runningCount =
307 (projection?.subagents.filter(
308 (agent) => agent.childThreadId === null && agent.status === "running",
309 ).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
310
311 if (relationshipRows.length === 0 && runningCount === 0) {
312 return null;
313 }
314
315 const openThread = (threadId: ThreadId) => {
316 void navigate({
317 to: "/$environmentId/$threadId",
318 params: buildThreadRouteParams(scopeThreadRef(props.environmentId, threadId)),
319 });
320 };
321
322 const merge = async () => {
323 if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
324 setBusyAction("merge");
325 const result = await mergeBack({
326 environmentId: props.environmentId,
327 input: {
328 sourceThreadId: props.threadId,
329 targetThreadId: mergeTargetThreadId,
330 runId: latestMergeBackRun.id,
331 },
332 });
333 setBusyAction(null);
334 if (result._tag === "Success") openThread(mergeTargetThreadId);
335 };
336
337 const detach = async () => {
338 if (!canDetach || busyAction !== null) return;
339 setBusyAction("detach");
340 await stopSession({
341 environmentId: props.environmentId,
342 input: { threadId: props.threadId },
343 });
344 setBusyAction(null);
345 };
346
347 const stopSubagent = async (
348 childThreadId: ThreadId,
349 agent: Pick<OrchestrationV2Subagent, "id" | "origin" | "threadId">,
350 ) => {
351 if (stoppingId !== null) return;
352 setStoppingId(childThreadId);
353 const result = await interruptTurn({
354 environmentId: props.environmentId,
355 input:
356 agent.origin === "provider_native"
357 ? { threadId: agent.threadId, subagentId: agent.id }
358 : { threadId: childThreadId },
359 });
360 setStoppingId(null);
361 if (result._tag === "Failure") {
362 toastManager.add({ type: "error", title: "Could not stop subagent" });
363 }
364 };
365
366 const stopWorkflow = async (subagentId: string) => {
367 if (stoppingId !== null) return;
368 setStoppingId(subagentId);
369 const result = await stopWorkflowCommand({
370 environmentId: props.environmentId,
371 input: { threadId: props.threadId, subagentId: NodeId.make(subagentId) },
372 });
373 setStoppingId(null);
374 if (result._tag === "Failure") {
375 toastManager.add({ type: "error", title: "Could not stop workflow" });
376 }
377 };
378
379 const parentTitle =
380 mergeTargetThreadId === null
381 ? null
382 : (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
383
384 return (
385 <ThreadDetailsSection
386 headingId="thread-details-lineage-heading"
387 title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
388 data-thread-relationships-panel
389 actions={
390 canDetach ? (
391 <Menu>
392 <MenuTrigger
393 render={
394 <ThreadDetailsControl
395 size="icon-xs"
396 variant="ghost"
397 part="icon"
398 aria-label="More thread actions"
399 disabled={busyAction !== null}
400 />
401 }
402 >
403 <MoreHorizontalIcon className="size-3.5" />
404 </MenuTrigger>
405 <MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
406 <MenuItem onClick={() => void detach()}>
407 <UnplugIcon className="size-3.5" />
408 Disconnect agent session
409 </MenuItem>
410 </MenuPopup>
411 </Menu>
412 ) : null
413 }
414 >
415 {groups.map((group) => (
416 <ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
417 {(visibleRows) =>
418 visibleRows.map(({ threadId, edge }) => {
419 const node = graph.nodes.get(threadId);
420 const isSubagent = edge.kind === "subagent";
421 const isMergeTarget = threadId === mergeTargetThreadId;
422 const isParent = isParentThreadRelationship(edge, props.threadId);
423 const rowStatus = threadRelationshipRowStatus(graph, { threadId, edge });
424 const RelationshipIcon = isParent
425 ? CornerLeftUpIcon
426 : isSubagent
427 ? BotIcon
428 : GitForkIcon;
429 const relationship = relationshipLabel(edge, props.threadId);
430 const projectedAgent =
431 isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
432 const workflowGroup =
433 projectedAgent === undefined
434 ? undefined
435 : workflowGroupsById.get(projectedAgent.id);
436 const agent = workflowGroup
437 ? projectedAgent
438 : currentSubagent(projectedAgent, node?.thread);
439 const failed = rowStatus === "failed" || rowStatus === "error";
440 const canStop =
441 agent &&
442 (agent.origin === "app_owned" ||
443 (agent.origin === "provider_native" &&
444 agent.driver === "claudeAgent" &&
445 agent.runId != null &&
446 agent.nativeTaskRef?.strength === "strong" &&
447 agent.nativeTaskRef.nativeId !== null &&
448 ["pending", "running", "waiting"].includes(agent.nativeStatus))) &&
449 agent.startedAt &&
450 ["pending", "running", "waiting"].includes(agent.status);
451 const threadTitle = relationshipThreadTitle({
452 title:
453 workflowGroup?.workflow.workflowName ??
454 node?.thread?.title ??
455 agent?.title ??
456 threadId,
457 isSubagent,
458 });
459 const provider = providers?.find(
460 (entry) =>
461 entry.instanceId ===
462 (agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
463 );
464 const providerDriver = agent?.driver ?? provider?.driver;
465 const canStopWorkflow =
466 canOperateWorkflow &&
467 workflowGroup?.workflow.status === "running" &&
468 agent?.origin === "provider_native" &&
469 providerDriver === "claudeAgent";
470 const trailingVisibilityClass = (workflowGroup ? canStopWorkflow : canStop)
471 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
472 : "";
473 const project = projects.find((project) => project.id === node?.thread?.projectId);
474 const relationshipHint = node?.missing
475 ? "This related thread is unavailable"
476 : `Open ${relationship.toLowerCase()} in this chat`;
477 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
478 const relationshipTooltip = agent ? (
479 <SubagentTooltipContent
480 title={threadTitle}
481 model={agent.model}
482 providerInstanceId={agent.providerInstanceId}
483 origin={agent.origin}
484 modelSelection={agent.modelSelection}
485 provider={provider}
486 providers={providers}
487 driver={providerDriver}
488 elapsed={<AgentElapsed agent={agent} />}
489 status={agent.status}
490 result={agent.result}
491 progress={agent.progress}
492 parentThread={currentThread ?? undefined}
493 childThread={node?.thread ?? undefined}
494 parentProject={currentProject}
495 childProject={project}
496 />
497 ) : (
498 relationshipHint
499 );
500 const relationshipContent = (
501 <>
502 <ThreadRelationshipIcon
503 driver={isSubagent && !isParent ? providerDriver : undefined}
504 provider={provider}
505 fallbackIcon={RelationshipIcon}
506 status={rowStatus}
507 />
508 <span className="min-w-0 flex-1">
509 <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
510 {threadTitle}
511 </span>
512 </span>
513 {agent ? null : (
514 <ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
515 )}
516 {agent &&
517 !failed &&
518 (deriveSubagentElapsedMs(agent, 0) !== null || canStopWorkflow) ? (
519 <span
520 className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${canStopWorkflow ? "min-w-6 text-end" : ""} ${trailingVisibilityClass}`}
521 >
522 <AgentElapsed agent={agent} compact />
523 </span>
524 ) : !isMergeTarget ? (
525 <span
526 className={
527 workflowGroup
528 ? "sr-only"
529 : `shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`
530 }
531 >
532 {threadRelationshipStatusLabel(rowStatus)}
533 </span>
534 ) : null}
535 </>
536 );
537 const relationshipLink = (
538 <Tooltip>
539 <TooltipTrigger
540 delay={200}
541 render={
542 <ThreadDetailsControl
543 size="sm"
544 variant="ghost"
545 part={workflowGroup ? "primary" : "row"}
546 disabled={node?.missing === true}
547 onClick={() => openThread(threadId)}
548 />
549 }
550 >
551 {relationshipContent}
552 </TooltipTrigger>
553 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
554 </Tooltip>
555 );
556 if (workflowGroup && agent) {
557 return (
558 <ThreadLineageWorkflowRow
559 key={threadId}
560 group={workflowGroup}
561 providerInstanceId={agent.providerInstanceId}
562 provider={provider}
563 providers={providers}
564 driver={providerDriver}
565 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
566 isThreadAvailable={(memberThreadId) =>
567 graph.nodes.get(memberThreadId as ThreadId)?.missing === false
568 }
569 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
570 stopping={stoppingId === agent.id}
571 stopDisabled={stoppingId !== null}
572 header={relationshipLink}
573 />
574 );
575 }
576 return (
577 <li key={threadId} className="group relative flex h-8 items-center rounded-lg">
578 {isMergeTarget ? (
579 <div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
580 <Tooltip>
581 <TooltipTrigger
582 delay={200}
583 render={
584 <ThreadDetailsControl
585 size="sm"
586 variant="ghost"
587 part="primary"
588 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
589 disabled={node?.missing === true}
590 onClick={() => openThread(threadId)}
591 />
592 }
593 >
594 {relationshipContent}
595 </TooltipTrigger>
596 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
597 </Tooltip>
598 <span
599 aria-hidden="true"
600 className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
601 />
602 <Tooltip>
603 <TooltipTrigger
604 render={
605 <ThreadDetailsControl
606 size="sm"
607 variant="ghost"
608 part="secondary"
609 aria-label={
610 parentTitle
611 ? `Merge back to ${parentTitle}`
612 : "Merge back to source conversation"
613 }
614 disabled={!canMerge || busyAction !== null}
615 onClick={() => void merge()}
616 >
617 {busyAction === "merge" ? (
618 <LoaderCircleIcon className="size-3 animate-spin" />
619 ) : (
620 <PullRequestGlyph.merged className="size-3" />
621 )}
622 </ThreadDetailsControl>
623 }
624 />
625 <TooltipPopup side="left">
626 {latestMergeBackRun === null
627 ? "Complete a run in this fork before merging it back"
628 : parentTitle
629 ? `Merge this conversation back into ${parentTitle}`
630 : "Merge this conversation back into its source"}
631 </TooltipPopup>
632 </Tooltip>
633 <span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
634 {threadRelationshipStatusLabel(rowStatus)}
635 </span>
636 </div>
637 ) : (
638 relationshipLink
639 )}
640 {canStop && agent ? (
641 <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">
642 <Tooltip>
643 <TooltipTrigger
644 render={
645 <ThreadDetailsControl
646 size="icon-xs"
647 variant="ghost"
648 part="icon"
649 tone="destructive"
650 aria-label={`Stop subagent ${threadTitle}`}
651 disabled={stoppingId !== null}
652 onClick={() => void stopSubagent(threadId, agent)}
653 />
654 }
655 >
656 {stoppingId === threadId ? (
657 <LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
658 ) : (
659 <SquareIcon aria-hidden className="size-3 fill-current" />
660 )}
661 </TooltipTrigger>
662 <TooltipPopup side="left">Stop subagent</TooltipPopup>
663 </Tooltip>
664 </div>
665 ) : null}
666 </li>
667 );
668 })
669 }
670 </ThreadLineageGroup>
671 ))}
672 </ThreadDetailsSection>
673 );
674}