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