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