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