Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadRelationshipsControl.tsx

672 lines27.5 KB

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