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 {/*
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" | "threadId">,
370 ) => {
371 if (stoppingId !== null) return;
372 setStoppingId(childThreadId);
373 const result = await interruptTurn({
374 environmentId: props.environmentId,
375 input: { threadId: agent.threadId, subagentId: agent.id },
376 });
377 setStoppingId(null);
378 if (result._tag === "Failure") {
379 toastManager.add({ type: "error", title: "Could not stop subagent" });
380 }
381 };
382
383 const stopWorkflow = async (subagentId: string) => {
384 if (stoppingId !== null) return;
385 setStoppingId(subagentId);
386 const result = await stopWorkflowCommand({
387 environmentId: props.environmentId,
388 input: { threadId: props.threadId, subagentId: NodeId.make(subagentId) },
389 });
390 setStoppingId(null);
391 if (result._tag === "Failure") {
392 toastManager.add({ type: "error", title: "Could not stop workflow" });
393 }
394 };
395
396 const parentTitle =
397 mergeTargetThreadId === null
398 ? null
399 : (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
400
401 return (
402 <ThreadDetailsSection
403 headingId="thread-details-lineage-heading"
404 title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
405 data-thread-relationships-panel
406 actions={
407 canDetach ? (
408 <Menu>
409 <MenuTrigger
410 render={
411 <ThreadDetailsControl
412 size="icon-xs"
413 variant="ghost"
414 part="icon"
415 aria-label="More thread actions"
416 disabled={busyAction !== null}
417 />
418 }
419 >
420 <MoreHorizontalIcon className="size-3.5" />
421 </MenuTrigger>
422 <MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
423 <MenuItem onClick={() => void detach()}>
424 <UnplugIcon className="size-3.5" />
425 Disconnect agent session
426 </MenuItem>
427 </MenuPopup>
428 </Menu>
429 ) : null
430 }
431 >
432 {groups.map((group) => (
433 <ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
434 {(visibleRows) =>
435 visibleRows.map(({ threadId, edge }) => {
436 const node = graph.nodes.get(threadId);
437 const isSubagent = edge.kind === "subagent";
438 const isMergeTarget = threadId === mergeTargetThreadId;
439 const isParent = isParentThreadRelationship(edge, props.threadId);
440 const rowStatus =
441 (isParent && threadId === parentRef?.threadId
442 ? (node?.thread?.activityRunStatus ?? parentNativeStatus)
443 : undefined) ?? threadRelationshipRowStatus(graph, { threadId, edge });
444 const RelationshipIcon = isParent
445 ? CornerLeftUpIcon
446 : isSubagent
447 ? BotIcon
448 : GitForkIcon;
449 const relationship = relationshipLabel(edge, props.threadId);
450 const projectedAgent =
451 isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
452 const workflowGroup =
453 projectedAgent === undefined
454 ? undefined
455 : workflowGroupsById.get(projectedAgent.id);
456 const agent = workflowGroup
457 ? projectedAgent
458 : currentSubagent(projectedAgent, node?.thread);
459 const failed = rowStatus === "failed" || rowStatus === "error";
460 const canStop =
461 agent &&
462 (agent.origin === "app_owned" ||
463 (agent.origin === "provider_native" &&
464 agent.driver === "claudeAgent" &&
465 agent.runId != null &&
466 agent.nativeTaskRef?.strength === "strong" &&
467 agent.nativeTaskRef.nativeId !== null &&
468 ["pending", "running", "waiting"].includes(agent.nativeStatus))) &&
469 agent.startedAt &&
470 ["pending", "running", "waiting"].includes(agent.status);
471 const threadTitle = relationshipThreadTitle({
472 title:
473 workflowGroup?.workflow.workflowName ??
474 node?.thread?.title ??
475 agent?.title ??
476 threadId,
477 isSubagent,
478 });
479 const provider = providers?.find(
480 (entry) =>
481 entry.instanceId ===
482 (agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
483 );
484 const providerDriver = agent?.driver ?? provider?.driver;
485 const canStopWorkflow =
486 canOperateWorkflow &&
487 workflowGroup?.workflow.status === "running" &&
488 agent?.origin === "provider_native" &&
489 providerDriver === "claudeAgent";
490 const trailingVisibilityClass = (workflowGroup ? canStopWorkflow : canStop)
491 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
492 : "";
493 const project = projects.find((project) => project.id === node?.thread?.projectId);
494 const relationshipHint = node?.missing
495 ? "This related thread is unavailable"
496 : `Open ${relationship.toLowerCase()} in this chat`;
497 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
498 const relationshipTooltip = agent ? (
499 <SubagentTooltipContent
500 title={threadTitle}
501 model={agent.model}
502 providerInstanceId={agent.providerInstanceId}
503 origin={agent.origin}
504 modelSelection={agent.modelSelection}
505 provider={provider}
506 providers={providers}
507 driver={providerDriver}
508 elapsed={<AgentElapsed agent={agent} />}
509 status={agent.status}
510 result={agent.result}
511 progress={agent.progress}
512 parentThread={currentThread ?? undefined}
513 childThread={node?.thread ?? undefined}
514 parentProject={currentProject}
515 childProject={project}
516 />
517 ) : (
518 relationshipHint
519 );
520 const relationshipContent = (
521 <>
522 <ThreadRelationshipIcon
523 driver={isSubagent && !isParent ? providerDriver : undefined}
524 provider={provider}
525 fallbackIcon={RelationshipIcon}
526 status={rowStatus}
527 />
528 <span className="min-w-0 flex-1">
529 <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
530 {threadTitle}
531 </span>
532 </span>
533 {agent ? null : (
534 <ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
535 )}
536 {agent &&
537 !failed &&
538 (deriveSubagentElapsedMs(agent, 0) !== null || canStopWorkflow) ? (
539 <span
540 className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${canStopWorkflow ? "min-w-6 text-end" : ""} ${trailingVisibilityClass}`}
541 >
542 <AgentElapsed agent={agent} compact />
543 </span>
544 ) : !isMergeTarget ? (
545 <span
546 className={
547 workflowGroup
548 ? "sr-only"
549 : `shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`
550 }
551 >
552 {threadRelationshipStatusLabel(rowStatus)}
553 </span>
554 ) : null}
555 </>
556 );
557 const relationshipLink = (
558 <Tooltip>
559 <TooltipTrigger
560 delay={200}
561 render={
562 <ThreadDetailsControl
563 size="sm"
564 variant="ghost"
565 part={workflowGroup ? "primary" : "row"}
566 disabled={node?.missing === true}
567 onClick={() => openThread(threadId)}
568 />
569 }
570 >
571 {relationshipContent}
572 </TooltipTrigger>
573 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
574 </Tooltip>
575 );
576 if (workflowGroup && agent) {
577 return (
578 <ThreadLineageWorkflowRow
579 key={threadId}
580 group={workflowGroup}
581 providerInstanceId={agent.providerInstanceId}
582 provider={provider}
583 providers={providers}
584 driver={providerDriver}
585 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
586 isThreadAvailable={(memberThreadId) =>
587 graph.nodes.get(memberThreadId as ThreadId)?.missing === false
588 }
589 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
590 stopping={stoppingId === agent.id}
591 stopDisabled={stoppingId !== null}
592 header={relationshipLink}
593 />
594 );
595 }
596 return (
597 <li key={threadId} className="group relative flex h-8 items-center rounded-lg">
598 {isMergeTarget ? (
599 <div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
600 <Tooltip>
601 <TooltipTrigger
602 delay={200}
603 render={
604 <ThreadDetailsControl
605 size="sm"
606 variant="ghost"
607 part="primary"
608 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
609 disabled={node?.missing === true}
610 onClick={() => openThread(threadId)}
611 />
612 }
613 >
614 {relationshipContent}
615 </TooltipTrigger>
616 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
617 </Tooltip>
618 <span
619 aria-hidden="true"
620 className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
621 />
622 <Tooltip>
623 <TooltipTrigger
624 render={
625 <ThreadDetailsControl
626 size="sm"
627 variant="ghost"
628 part="secondary"
629 aria-label={
630 parentTitle
631 ? `Merge back to ${parentTitle}`
632 : "Merge back to source conversation"
633 }
634 disabled={!canMerge || busyAction !== null}
635 onClick={() => void merge()}
636 >
637 {busyAction === "merge" ? (
638 <LoaderCircleIcon className="size-3 animate-spin" />
639 ) : (
640 <PullRequestGlyph.merged className="size-3" />
641 )}
642 </ThreadDetailsControl>
643 }
644 />
645 <TooltipPopup side="left">
646 {latestMergeBackRun === null
647 ? "Complete a run in this fork before merging it back"
648 : parentTitle
649 ? `Merge this conversation back into ${parentTitle}`
650 : "Merge this conversation back into its source"}
651 </TooltipPopup>
652 </Tooltip>
653 <span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
654 {threadRelationshipStatusLabel(rowStatus)}
655 </span>
656 </div>
657 ) : (
658 relationshipLink
659 )}
660 {canStop && agent ? (
661 <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">
662 <Tooltip>
663 <TooltipTrigger
664 render={
665 <ThreadDetailsControl
666 size="icon-xs"
667 variant="ghost"
668 part="icon"
669 tone="destructive"
670 aria-label={`Stop subagent ${threadTitle}`}
671 disabled={stoppingId !== null}
672 onClick={() => void stopSubagent(threadId, agent)}
673 />
674 }
675 >
676 {stoppingId === threadId ? (
677 <LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
678 ) : (
679 <SquareIcon aria-hidden className="size-3 fill-current" />
680 )}
681 </TooltipTrigger>
682 <TooltipPopup side="left">Stop subagent</TooltipPopup>
683 </Tooltip>
684 </div>
685 ) : null}
686 </li>
687 );
688 })
689 }
690 </ThreadLineageGroup>
691 ))}
692 </ThreadDetailsSection>
693 );
694}